using Hotline.CallCenter.BlackLists;
using Hotline.CallCenter.Tels.CallTelDomain;
using Hotline.Import;
using Hotline.JudicialManagement;
using Hotline.Orders;
using Hotline.Push.FWMessage;
using Hotline.Push.Notifies;
using Hotline.Settings;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Ai;
using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Dtos.JudicialManagement;
using Hotline.Share.Dtos.OrderExportWord;
using Hotline.Share.Dtos.Org;
using Hotline.Share.Dtos.Push.FWMessage;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Dtos.TrCallCenter;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums.Order;
using Mapster;
using XF.Domain.Entities;
using Hotline.Share.Tools;
using Hotline.ThirdAccountDomainServices;

namespace Hotline.Application.Mappers
{
    public partial class MapperConfigs : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            //config.ForType<SystemLog, SystemLogDto>()
            //    .Map(dest => dest.ExecuteParam,
            //    src => src.ExecuteParam == null 
            //    ? null
            //    : src.ExecuteParam.ToJson().FromJson<Dictionary<string, object>>());

            config.ForType<ThirdTokenInDto, ThirdAccount>()
                .Map(d => d.AppType, x => x.AppType)
                .Map(d => d.AccountType, x => x.ThirdType);
                
            config.ForType<ExcelContent, Order>()
                .Map(d => d.FirstVisitResult, x => x.VisitResult)
                .IgnoreNullValues(true);

            config.ForType<SystemDicData, Kv>()
                .Map(s => s.Key, d => d.DicDataValue)
                .Map(s => s.Value, d => d.DicDataName);

            config.ForType<SystemDicDataOutDto, Kv>()
                .Map(s => s.Key, d => d.DicDataValue)
                .Map(s => s.Value, d => d.DicDataName);

            config.ForType<Message, ReceiveMessageNotify>()
                .Map(m => m.NotifyDto, d => d);

            config.ForType<SystemDicData, SystemDicDataOutDto>()
                .Map(m => m.Id, n => n.Id)
                .Map(m => m.DicDataName, n => n.DicDataName)
                .Map(m => m.DicDataValue, n => n.DicDataValue)
                .Map(m => m.Children, n => n.Children);

            config.ForType<Tr.Sdk.Tels.QueryTelResponse, TelOutDto>()
                .Map(m => m.TelPwd, x => x.Password)
                .Map(m =>m.Queue, x => x.QueueId);

            config.ForType<QueryTelResponse, TelOutDto>()
                .Map(m => m.TelPwd, x => x.Password)
                .Map(m => m.Queue, x => x.QueueId);

            config.ForType<ExcelContent, Order>()
                .Map(d => d.FirstVisitResult, x => x.VisitResult)
                .IgnoreNullValues(true);

            config.ForType<TimeLimitSettingInventory, TimeConfig>()
                .Map(d => d.TimeLimitSettingAttributeId, m => m.Id)
                .Map(d => d.Count, m => m.TimeValue);
            config.ForType<TimeResult, ExpiredTimeWithConfig>()
                .Map(d => d.ExpiredTime, x => x.EndTime)
                .Map(d => d.NearlyExpiredTime, x => x.NearlyExpiredTime)
                .Map(d => d.NearlyExpiredTimeOne, x => x.NearlyExpiredTimeOne);
                
            config.ForType<TimeLimitSetting, TimeConfig>()
                .Map(d => d.Count, x => x.TimeValue);

            config.ForType<ThirdAccount, SnapshotUserInfoOutDto>();
            config.ForType<ThirdTokenOutDto, ThirdAccount>()
                .Map(d => d.OpenId, m => m.OpenId);

            config.ForType<AddBlacklistDto, Blacklist>()
                .Ignore(d => d.Expired)
                .AfterMapping((s, t) => t.InitExpired());

            config.ForType<Message, MessageDataDto>()
               .Map(d => d.SendUser, x => x.CreatorName)
               .Map(d => d.SendOrganize, x => x.CreatorOrgName)
               .IgnoreIf((s, d) => s.Order == null, x => x.OrderId)
               .IgnoreIf((s, d) => s.Order == null, x => x.OrderNo);

            #region org

            config.ForType<UpdateOrgDto, SystemOrganize>()
                .Ignore(d => d.Id)
                .Ignore(d => d.ParentId)
                .Ignore(d => d.ParentName);

            #endregion

            

            //config.ForType<EnforcementOrders, EnforcementOrderListDto>()
            //    .Map(d => d.Id, x => x.Id)
            //    .Map(d => d.WorkflowId, x => x.Order.WorkflowId)
            //    .Map(d => d.Status, x => x.Order.Status)
            //    .Map(d => d.No, x => x.Order.No)
            //    .Map(d => d.SourceChannel, x => x.Order.SourceChannel)
            //    .Map(d => d.SourceChannelCode, x => x.Order.SourceChannelCode)
            //    .Map(d => d.FromPhone, x => x.Order.FromPhone)
            //    .Map(d => d.TransferPhone, x => x.Order.TransferPhone)
            //    .Map(d => d.FromName, x => x.Order.FromName)
            //    .Map(d => d.Contact, x => x.Order.Contact)
            //    .Map(d => d.AcceptType, x => x.Order.AcceptType)
            //    .Map(d => d.AcceptTypeCode, x => x.Order.AcceptTypeCode)
            //    .Map(d => d.EmergencyLevel, x => x.Order.EmergencyLevel)
            //    .Map(d => d.Title, x => x.Order.Title)
            //    .Map(d => d.HotspotId, x => x.Order.HotspotId)
            //    .Map(d => d.HotspotName, x => x.Order.HotspotName)
            //    .Map(d => d.HotspotSpliceName, x => x.Order.HotspotSpliceName)
            //    .Map(d => d.CreationTime, x => x.Order.CreationTime)
            //    .Map(d => d.IsProvince, x => x.Order.IsProvince)
            //    .Map(d => d.ProvinceNo, x => x.Order.ProvinceNo)
            //    .Map(d => d.ActualHandleStepName, x => x.Order.ActualHandleStepName)
            //    .Map(d => d.ActualHandleTime, x => x.Order.ActualHandleTime)
            //    .Map(d => d.ExpiredTime, x => x.Order.ExpiredTime)
            //    .Map(d => d.NearlyExpiredTime, x => x.Order.NearlyExpiredTime)
            //    .Map(d => d.FiledTime, x => x.Order.FiledTime)
            //    .Map(d => d.OrgLevelOneCode, x => x.Order.OrgLevelOneCode)
            //    .Map(d => d.OrgLevelOneName, x => x.Order.OrgLevelOneName)
            //    .Map(d => d.ActualHandlerName, x => x.Order.ActualHandlerName)
            //    .Map(d => d.StartTime, x => x.Order.StartTime)
            //    .Map(d => d.ActualHandleOrgName, x => x.Order.ActualHandleOrgName)
            //    .Map(d => d.ActualHandleOrgCode, x => x.Order.ActualHandleOrgCode)
            //    .Map(d => d.IsEnforcementOrder, x => x.IsEnforcementOrder)
            //    .Map(d => d.IsPassTheBuckOrder, x => x.IsPassTheBuckOrder)
            //    .Map(d => d.IsTheClueTrue, x => x.IsTheClueTrue)
            //    .Map(d => d.EventTypeName, x => x.EventTypeName)
            //    .Map(d => d.EventTypeId, x => x.EventTypeId)
            //    .Map(d => d.EventTypeSpliceName, x => x.EventTypeSpliceName)
            //     ;

            config.ForType<Order, OrderSubmissionForm>()
             .Map(d => d.FromGender, x => x.FromGender == EGender.Male ? "男" : x.FromGender == EGender.Female ? "女" : "未知")
             .Map(d => d.CreationTime, x => x.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"))
             .Map(d => d.CenterToOrgTime, x => x.CenterToOrgTime == null ? "" : x.CenterToOrgTime.Value.ToString("yyyy-MM-dd HH:mm:ss"))
             .Map(d => d.ExpiredTime, x => x.ExpiredTime == null ? "" : x.ExpiredTime.Value.ToString("yyyy-MM-dd HH:mm:ss"))
             ;
        }
    }
}
