using Hotline.Share.Dtos.File;
using Hotline.Share.Enums.JudicialManagement;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Settings;
using System.ComponentModel;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.JudicialManagement
{
    /// <summary>
    /// 修改
    /// </summary>
    public class JudicialManagementAddOrderDto : Position
    {
        /// <summary>
        /// 来源渠道（电话、网站、APP等）
        /// </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 EGender FromGender { get; set; }

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

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

        public string? ContactMask { get; set; }

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

        public string? AcceptTypeCode { get; set; }

        public string Title { get; set; }

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

        public string? HotspotName { get; set; }

        public string? HotspotSpliceName { get; set; }

        /// <summary>
        /// 外部数据（为前端提供级联功能）
        /// </summary>
        public string? HotspotExternal { get; set; }

        /// <summary>
        /// 附件列表
        /// </summary>
        public List<FileDto> Files { get; set; } = new();

        /// <summary>
        /// 诉求内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 工单来源
        /// </summary>
        public EOrderSoure? OrderSoure { get; set; }

        /// <summary>
        /// 是否行政执法类
        /// </summary>
        public bool? IsEnforcementOrder { get; set; }

        /// <summary>
        /// 执法部门
        /// </summary>
        public List<Kv> EnforcementOrdersHandler { get; set; }

        public string EnforcementOrdersHandlerText => GetText();

        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;
        }
    }

    /// <summary>
    /// 编辑
    /// </summary>
    public class JudicialManagementUpdateOrderDto : JudicialManagementAddOrderDto
    {
        public string Id { get; set; }
    }

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

        /// <summary>
        /// 是否推诿
        /// </summary>
        public bool IsPassTheBuckOrder { get; set; }

        /// <summary>
        /// 线索是否属实
        /// </summary>
        public bool? IsTheClueTrue { get; set; }

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

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

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

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

        /// <summary>
        /// 同步省工单编号和省上传下来的工单都用这个字段
        /// </summary>
        public string? ProvinceNo { get; set; }

        /// <summary>
        /// 市民查询密码
        /// </summary>
        public string? Password { 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<FileDto>? Additions { get; set; } = new();
        public List<FileJson>? FileJson { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }

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

        /// <summary>
        /// 交办时间
        /// </summary>
        public DateTime? CenterToOrgTime {  get; set; }

        /// <summary>
        /// 接办部门
        /// </summary>
        public string? ActualHandleOrgName {  get; set; }

        /// <summary>
        /// 接办时间
        /// </summary>
        public DateTime? ActualHandleTime {  get; set; }

        /// <summary>
        /// 办理时间限制(如：24小时、7个工作日)
        /// </summary>
        public string? TimeLimit { get; set; }

        public int? TimeLimitCount { get; set; }

        public ETimeType? TimeLimitUnit { get; set; }

        /// <summary>
        /// 工单期满时间
        /// </summary>
        public DateTime? ExpiredTime {  get; set; }

        /// <summary>
        /// 部门是否解决
        /// </summary>
        public bool IsResolved { get; set; }

        /// <summary>
        /// 部门处理结果
        /// </summary>
        public string IsResolvedText => IsResolved ? "已解决" : "未解决";

        /// <summary>
        /// 中心意见
        /// </summary>
        public string? CenterOpinion { get; set; }

        /// <summary>
        /// 承办意见
        /// </summary>
        public string? FileOpinion { get; set; }

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

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

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

    public class AssociatedLawEnforcementAgenciesDto
    {
        public string Id { get; set; }

        /// <summary>
        /// 执法部门
        /// </summary>
        public List<Kv> LawEnforcementAgencies { get; set; }
    }
}
