using Hotline.Share.Dtos;
using Hotline.Share.Dtos.File;
using Hotline.Share.Enums.JudicialManagement;
using Hotline.Share.Enums.Order;
using Hotline.Share.Tools;
using SqlSugar;
using XF.Domain.Extensions;
using XF.Domain.Repository;

namespace Hotline.JudicialManagement
{
    public class JudicialManagementOrders : PositionEntity
    {
        /// <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>
        [SugarColumn(ColumnDescription = "联系电话", IsNullable = true)]
        public string? Contact { get; set; }

        [SugarColumn(ColumnDescription = "联系电话脱敏", IsNullable = true)]
        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>
        [SugarColumn(ColumnDataType = "json", IsJson = true)]
        public List<FileDto>? Additions { get; set; } = new();

        /// <summary>
        /// 诉求内容
        /// </summary>
        [SugarColumn(ColumnDataType = "varchar(8000)")]
        public string Content { get; set; }

        /// <summary>
        /// 工单编码（20220101000001）
        /// </summary>
        public string? No { 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; }

        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
        public List<FileJson>? FileJson { get; set; }

        /// <summary>
        /// 是否统计
        /// </summary>
        public bool IsItCounted { get; set; } = true;

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

        /// <summary>
        /// 接办部门
        /// </summary>
        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
        public List<Kv> EnforcementOrdersHandler { get; set; }

        /// <summary>
        /// 执法部门
        /// </summary>
        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
        public List<Kv> LawEnforcementAgencies { 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 bool? IsEnforcementOrder { get; set; }

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

        public void Init()
        {
            if (!string.IsNullOrEmpty(Contact))
                ContactMask = Contact.MaskPhoneNumber();
        }

        public void AutoAccept(string userId, string? userName, string? staffNo, string? acceptorOrgCode, string? acceptorOrgName)
        {
            AcceptorId = userId;
            AcceptorName = userName;
            AcceptorStaffNo = staffNo;
            AcceptorOrgCode = acceptorOrgCode;
            AcceptorOrgName = acceptorOrgName;
        }



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

    }
    public abstract class PositionEntity : FullStateEntity
    {
        /// <summary>
        /// 经度
        /// </summary>
        [SugarColumn(ColumnDescription = "经度")]
        public double? Longitude { get; set; }

        /// <summary>
        /// 维度
        /// </summary>
        [SugarColumn(ColumnDescription = "纬度")]
        public double? Latitude { get; set; }

        /// <summary>
        /// 行政区划编码
        /// </summary>
        [SugarColumn(ColumnDescription = "行政区划编码")]
        public string? AreaCode { 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? Street { get; set; }

        /// <summary>
        /// 行政区划地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 完整地址
        /// </summary>
        public string? FullAddress { get; set; }
    }

}