using Hotline.Configurations;

namespace Hotline.DI
{
    [AttributeUsage(AttributeTargets.Class)]
    public class InjectionAttribute : Attribute
    {
        /// <summary>
        /// 适用范围
        /// </summary>
        public EAppScope AppScopes { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enable { get; set; } = true;

        /// <summary>
        /// handler的业务类型
        /// </summary>
        public EEventHandlerType EventHandlerType { get; set; }

        /// <summary>
        /// value,value
        /// </summary>
        public string Label { get; set; }

        public bool IsEnable(string? appScope, string? callcenterType)
        {
            if (!Enable) return false;
            if (!string.IsNullOrEmpty(appScope))
            {
                return AppScopes.ToString()
                    .Split(',', StringSplitOptions.TrimEntries)
                    .Any(x => string.Compare(x, appScope, StringComparison.Ordinal) == 0);
            }

            if (!string.IsNullOrEmpty(callcenterType))
            {
                switch (EventHandlerType)
                {
                    case EEventHandlerType.CallCenter:
                        return Label == callcenterType;
                }
            }

            return true;
        }
    }

    public enum EEventHandlerType
    {
        CallCenter = 1
    }
}
