using Hotline.Share.Enums.Order;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.JudicialManagement
{
    public class EnforcementOrderListDto
    {
        /// <summary>
        /// 是否统计
        /// </summary>
        public bool IsItCounted { get; set; } = true;
        public string? IsItCountedText => CalcRate(IsItCounted);

        public string Id { get; set; }

        /// <summary>
        /// 工单编码（20220101000001）
        /// </summary>
        public string No { get; set; }

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

        /// <summary>
        /// 来电号码
        /// </summary>
        public string? FromPhone { get; set; }

        /// <summary>
        /// 转接号码（转接来源）
        /// </summary>
        public string? TransferPhone { get; set; }

        /// <summary>
        /// 来电/信人姓名
        /// </summary>
        public string? FromName { get; set; }

        /// <summary>
        /// 联系电话
        /// </summary>
        public string? Contact { get; set; }

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

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 热点
        /// </summary>
        public string? HotspotId { get; set; }
        public string? HotspotName { get; set; }
        public string? HotspotSpliceName { get; set; }

        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 省
        /// </summary>
        public string? Province { get; set; }

        /// <summary>
        /// 市
        /// </summary>
        public string? City { get; set; }

        /// <summary>
        /// 区/县  
        /// </summary>
        public string? County { get; set; }

        /// <summary>
        /// 乡镇(4级行政区划)
        /// </summary>
        public string? Town { get; set; }

        /// <summary>
        /// 省市区
        /// </summary>
        public string IncidentAddressText => IncidentAddress();

        /// <summary>
        /// 是否行政执法类
        /// </summary>
        public bool? IsEnforcementOrder { get; set; }
        public string? IsEnforcementOrderText => CalcRate(IsEnforcementOrder);

        /// <summary>
        /// 是否推诿
        /// </summary>
        public bool? IsPassTheBuckOrder { get; set; }
        public string? IsPassTheBuckOrderText => CalcRate(IsPassTheBuckOrder);

        /// <summary>
        /// 线索是否属实
        /// </summary>
        public bool? IsTheClueTrue { get; set; }
        public string? IsTheClueTrueText => CalcRate(IsTheClueTrue);

        /// <summary>
        /// 诉事项类型Id
        /// </summary>
        public string? EventTypeId { get; set; }

        /// <summary>
        /// 诉事项类型名称
        /// </summary>
        public string? EventTypeName { get; set; }

        /// <summary>
        /// 诉事项类型名称
        /// </summary>
        public string? EventTypeSpliceName { get; set; }

        /// <summary>
        /// 是否显示修改按钮
        /// </summary>
        public bool IsShowUpdateButton { get; set; }

        /// <summary>
        /// 受理人id
        /// </summary>
        public string? AcceptorId { get; set; }

        /// <summary>
        /// 受理人名称
        /// </summary>
        public string? AcceptorName { get; set; }

        /// <summary>
        /// 受理人工号
        /// </summary>
        public string? AcceptorStaffNo { get; set; }

        /// <summary>
        /// 受理人部门编码
        /// </summary>
        public string? AcceptorOrgCode { get; set; }

        /// <summary>
        /// 受理人部门名称
        /// </summary>
        public string? AcceptorOrgName { get; set; }

        /// <summary>
        /// 接办部门
        /// </summary>
        public List<Kv> EnforcementOrdersHandler { get; set; }
        public string EnforcementOrdersHandlerText => GetText();

        /// <summary>
        /// 执法部门
        /// </summary>
        public List<Kv> LawEnforcementAgencies { get; set; }
        public string LawEnforcementAgenciesText => GetLawEnforcementAgenciesText();

        public bool IsAddLawEnforcementAgencies => IsAddLawEnforcementAgenciesTe();
        public string GetText()
        {
            string strOrgName = "";
            if (EnforcementOrdersHandler != null && EnforcementOrdersHandler.Count > 0)
            {
                foreach (var item in EnforcementOrdersHandler)
                {
                    strOrgName += item.Key + ",";
                }
                if (!string.IsNullOrEmpty(strOrgName))
                    strOrgName = strOrgName.Substring(0, strOrgName.Length - 1);
            }
            return strOrgName;
        }

        public string GetLawEnforcementAgenciesText()
        {
            string strOrgName = "";
            if (LawEnforcementAgencies != null && LawEnforcementAgencies.Count > 0)
            {
                foreach (var item in LawEnforcementAgencies)
                {
                    strOrgName += item.Key + ",";
                }
                if (!string.IsNullOrEmpty(strOrgName))
                    strOrgName = strOrgName.Substring(0, strOrgName.Length - 1);
            }
            return strOrgName;
        }

        /// <summary>
        /// 如果执法部门为空，那么可以关联，如果执法部门不为空，则可以关联
        /// </summary>
        /// <returns></returns>
        public bool IsAddLawEnforcementAgenciesTe()
        {
            if (LawEnforcementAgencies != null && LawEnforcementAgencies.Count > 0)
                return false;
            return true;
        }

        /// <summary>
        /// 转换是否文本
        /// </summary>
        /// <returns></returns>
        public string CalcRate(bool? isRight)
        {
            if (isRight.HasValue && isRight.Value == true)
                return "是";
            else if (isRight.HasValue && isRight.Value == false)
                return "否";
            else
                return "";
        }

        /// <summary>
        /// 组装省市区
        /// </summary>
        /// <returns></returns>
        public string IncidentAddress()
        {
            return $"{Province}{City}{County}";
        }

        /// <summary>
        /// 个案类型
        /// </summary>
        public ECaseType? CaseType { get; set; }

        /// <summary>
        /// 个案类型
        /// </summary>
        public string CaseTypeDesc
        {
            get
            {
                return CaseType?.GetDescription()??string.Empty;
            }
        }
    }

    public class EnforcementOrgSatisfactionOrderListDto : EnforcementOrderListDto
    {
        /// <summary>
        /// 回访主表ID
        /// </summary>
        public string VisitId { get; set; }
    }

    public class EnforcementOldOrder
    {
        /// <summary>
        /// 工单Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 编号
        /// </summary>
        public string No { get; set; }

        /// <summary>
        /// 热点
        /// </summary>
        public string HotspotId { get; set; }

        /// <summary>
        /// 办结时间
        /// </summary>
        public DateTime? HandleTime { get; set; }

        /// <summary>
        /// 办理一级部门名称
        /// </summary>
        public string OrgLevelOneCode { get; set; }

        /// <summary>
        /// 实际办理部门
        /// </summary>
        public string ActualHandleOrgCode { get; set; }
    }
}
