using System;
using System.ComponentModel;
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
using TelegramBotBase.Interfaces;
namespace TelegramBotBase.MessageLoops;
///
/// This is a minimal message loop which will react to all update types and just calling the Load method.
///
public class MinimalMessageLoop : IMessageLoopFactory
{
private static readonly object EvUnhandledCall = new();
private readonly EventHandlerList _events = new();
public async Task MessageLoop(BotBase bot, IDeviceSession session, UpdateResult ur, MessageResult mr)
{
var update = ur.RawData;
mr.Device = session;
var activeForm = session.ActiveForm;
//Loading Event
await activeForm.Load(mr);
}
///
/// Will be called if no form handled this call
///
public event EventHandler UnhandledCall
{
add => _events.AddHandler(EvUnhandledCall, value);
remove => _events.RemoveHandler(EvUnhandledCall, value);
}
public void OnUnhandledCall(UnhandledCallEventArgs e)
{
(_events[EvUnhandledCall] as EventHandler)?.Invoke(this, e);
}
}