using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Settings;
using Hotline.Share.Tools;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Settings
{
    /// <summary>
    /// 计算期满时间所需要的 工单信息
    /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    /// !!!!!该类中的字段顺序很重要!!!!!!
    /// 字段的顺序等于期满条件的优先级
    /// 计算期满时间时, 会根据该类中字段顺序计算期满
    /// </summary>
    public class OrderTimeClacInfo
    {
        public const string BusCodeName = "AcceptTypeCode";

        public OrderTimeClacInfo()
        {
            
        }

        public OrderTimeClacInfo(string acceptTypeCode)
        {
            AcceptTypeCode = acceptTypeCode;
        }

        /// <summary>
        /// 受理类型代码
        /// </summary>
        public string? AcceptTypeCode { get; set; }

        /// <summary>
        /// 流程方向
        /// </summary>
        public EFlowDirection FlowDirection { get; set; }

        /// <summary>
        /// 24小时办结
        /// </summary>
        [NoCode] // 不需要查询 BusCode
        public bool Is24HoursComplete { get; set; }

        /// <summary>
        /// 热点分类类目名称
        /// </summary>
        [IsFuzzyQuery] // 模糊查询
        [NoCode] // 不需要查询 BusCode
        public string? HotspotSpliceName { get; set; }

        /// <summary>
        /// 来电/信人身份
        /// </summary>
        public EIdentityType? IdentityType { get; set; }

        /// <summary>
        /// 来源渠道
        /// </summary>
        public string? SourceChannel { get; set; }
    }

    public class TimeConfig
    {
        public TimeConfig()
        {

        }

        public TimeConfig(int count, ETimeType timeType)
        {
            Count = count;
            TimeType = timeType;
            TimeText = $"{count}个{timeType.GetDescription()}";
        }

        /// <summary>
        /// 命中的规则Id
        /// </summary>
        public string? TimeLimitSettingAttributeId { get; set; }

        public int Count { get; set; }
        public ETimeType TimeType { get; set; }

        private string timeText;
        public string TimeText
        {
            get
            {
                if (timeText.IsNullOrEmpty()) return $"{Count}个{TimeType.GetDescription()}";
                return timeText;
            }
            set
            {
                timeText = value;
            }
        }

        /// <summary>
        /// 超期时限百分比
        /// </summary>
        public int Percentage { get; set; }

        /// <summary>
        /// 超期时间百分比（第一级）
        /// </summary>
        public int PercentageOne { get; set; }

        /// <summary>
        /// 工作时间
        /// </summary>
        public IList<string>? WorkTime { get; set; }

        /// <summary>
        /// 收尾方式 0：不收尾  1：下班收尾 2：下一个工作日上班收尾
        /// </summary>
        public int? EndType { get; set; } = 0;
    }

    public class ExpiredTimeWithConfig : TimeConfig
    {
        public DateTime ExpiredTime { get; set; }

        /// <summary>
        /// 即将超期时间
        /// </summary>
        public DateTime NearlyExpiredTime { get; set; }

        /// <summary>
        /// 即将超期时间第一级
        /// </summary>
        public DateTime NearlyExpiredTimeOne { get; set; }
    }
}
