using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegrator.Filters.Components;
using Telegrator.Handlers.Components;
using Telegrator.MadiatorCore.Descriptors;
namespace Telegrator.Attributes.Components
{
///
/// Defines the 's and validator () of the that will process
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public abstract class UpdateHandlerAttributeBase : Attribute, IFilter
{
///
public bool IsCollectible => this.HasPublicProperties();
///
/// Gets an array of that this attribute can be attached to
///
public Type[] ExpectingHandlerType { get; private set; }
///
/// Gets an that handlers processes
///
public UpdateType Type { get; private set; }
///
/// Gets or sets importance of this in same pool
///
public int Importance { get; set; }
///
/// Gets or sets priority of this in same type handlers pool
///
public int Priority { get; set; }
public bool FormReport { get; set; }
///
/// Creates a new instance of
///
///
///
///
///
///
///
protected internal UpdateHandlerAttributeBase(Type[] expectingHandlerType, UpdateType updateType, int importance = 0)
{
if (expectingHandlerType == null)
throw new ArgumentNullException(nameof(expectingHandlerType));
if (expectingHandlerType.Any(type => !type.IsHandlerAbstract()))
throw new ArgumentException("One of expectingHandlerType is not a handler type", nameof(expectingHandlerType));
if (updateType == UpdateType.Unknown)
throw new Exception();
ExpectingHandlerType = expectingHandlerType;
Type = updateType;
Importance = importance;
}
///
/// Gets an of this from and
///
///
public DescriptorIndexer GetIndexer()
=> new DescriptorIndexer(0, this);
///
/// Validator () of the that will process
///
///
///
public abstract bool CanPass(FilterExecutionContext context);
}
}