using System;
using System.Collections.Generic;
using System.Reflection;
using FiestaBot.Instances.Handlers;

namespace FiestaBot.Login.Handlers
{
    internal class LoginPacketHandler : PacketHandlerAttribute
    {
        public LoginPacketHandler(byte Header, byte Type) : base(Header, Type) { }
    }

    internal class LoginHandlerLoader : HandlerLoader
    {
        public LoginHandlerLoader()
        {
            foreach (var PacketHandler in FilterAssembly.FindHandlers<LoginPacketHandler>())
            {
                LoginPacketHandler PacketAttribute = PacketHandler.PacketAttribute;

                MethodInfo PacketMethod = PacketHandler.MethodInfo;

                if (!Handlers.ContainsKey(PacketAttribute.Header)) { Handlers.Add(PacketAttribute.Header, new Dictionary<byte, MethodInfo>()); }

                if (!Handlers[PacketAttribute.Header].ContainsKey(PacketAttribute.Type)) { Handlers[PacketAttribute.Header].Add(PacketAttribute.Type, PacketMethod); }
            }
        }
    }
}
