using System;
using System.Collections.Generic;

namespace Stary.Evo
{
    [Obsolete("推荐使用 EnumEventSystem",false)]
    public class StringEventSystem
    {
        public static readonly StringEventSystem Global = new StringEventSystem();
        
        private Dictionary<string, IEasyEvent> mEvents = new Dictionary<string, IEasyEvent>();
        
        public IUnRegister Register(string key, Action onEvent)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent>();
                return easyEvent.Register(onEvent);
            }
            else
            {
                var easyEvent = new EasyEvent();
                mEvents.Add(key,easyEvent);
                return easyEvent.Register(onEvent);
            }
        }
        public IUnRegister Register<T>(string key, Action<T> onEvent)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T>>();
                return easyEvent.Register(onEvent);
            }
            else
            {
                var easyEvent = new EasyEvent<T>();
                mEvents.Add(key,easyEvent);
                return easyEvent.Register(onEvent);
            }
        }
        public IUnRegister Register<T1,T2>(string key, Action<T1,T2> onEvent)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2>>();
                return easyEvent.Register(onEvent);
            }
            else
            {
                var easyEvent = new EasyEvent<T1,T2>();
                mEvents.Add(key,easyEvent);
                return easyEvent.Register(onEvent);
            }
        }
        public IUnRegister Register<T1,T2,T3>(string key, Action<T1,T2,T3> onEvent)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2,T3>>();
                return easyEvent.Register(onEvent);
            }
            else
            {
                var easyEvent = new EasyEvent<T1,T2,T3>();
                mEvents.Add(key,easyEvent);
                return easyEvent.Register(onEvent);
            }
        }
        public IUnRegister Register(string key, Action<object[]> onEvent)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<object[]> >();
                return easyEvent.Register(onEvent);
            }
            else
            {
                var easyEvent = new EasyEvent<object[]> ();
                mEvents.Add(key,easyEvent);
                return easyEvent.Register(onEvent);
            }
        }
        public void UnRegister(string key, Action onEvent)
        {
            
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent>();
                easyEvent?.UnRegister(onEvent);
            }
        }
        public void UnRegister<T>(string key, Action<T> onEvent)
        {
            
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T>>();
                easyEvent?.UnRegister(onEvent);
            }
        }
        public void UnRegister<T1,T2>(string key, Action<T1,T2> onEvent)
        {
            
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2>>();
                easyEvent?.UnRegister(onEvent);
            }
        }
        public void UnRegister<T1,T2,T3>(string key, Action<T1,T2,T3> onEvent)
        {
            
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2,T3>>();
                easyEvent?.UnRegister(onEvent);
            }
        }
        public void UnRegister(string key, Action<object[]> onEvent)
        {
            
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<object[]>>();
                easyEvent?.UnRegister(onEvent);
            }
        }
        public void Send(string key)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent>();
                easyEvent?.Trigger();
            }
        }
        public void Send<T>(string key, T data)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T>>();
                easyEvent?.Trigger(data);
            }
        }
        public void Send<T1,T2>(string key, T1 data1, T2 data2)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2>>();
                easyEvent?.Trigger(data1,data2);
            }
        }
        public void Send<T1,T2,T3>(string key, T1 data1, T2 data2, T3 data3)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<T1,T2,T3>>();
                easyEvent?.Trigger(data1,data2,data3);
            }
        }
        public void Send(string key, object[] data)
        {
            if (mEvents.TryGetValue(key, out var e))
            {
                var easyEvent = e.As<EasyEvent<object[]>>();
                easyEvent?.Trigger(data);
            }
        }
        public void Dispose()
        {
            mEvents.Clear();
        }
    }
}