using Hotline.Orders;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.WebPortal;
using Hotline.Share.Enums.Order;
using Hotline.WebPortal;
using Mapster;

namespace Hotline.Application.Mappers
{
    public class WebPortalMapperConfigs : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            #region 门户网站数据

            //办件摘编列表
            config.ForType<OrderPublish, OrderListDto>()
               .Ignore(d => d.Source)
               .Map(d => d.FlowID, x => x.OrderId)
               .Map(d => d.FlowCode, x => x.Order.No)
               .Map(d => d.FlowPwd, x => x.Order.Password)
               .Map(d => d.FlowTitle, x => string.IsNullOrEmpty(x.ArrangeTitle) ? x.Order.Title : x.ArrangeTitle)
               .Map(d => d.FlowFromName, x => x.Order.SourceChannel)
               .Map(d => d.FlowPurTypeName, x => x.Order.AcceptType)
               .Map(d => d.ConTypeName, x => x.Order.HotspotName)
               .Map(d => d.FlowAddDate, x => x.Order.StartTime)
               .Map(d => d.PubDate, x => x.CreationTime)
               .Map(d => d.RSFlagName, x => x.Order.Status < EOrderStatus.Filed ? "办理中" : "办理完成")
          ;

            //办件摘编详情
            config.ForType<Order, OrderDetail>()
            .Map(d => d.FlowID, x => x.Id)
            .Map(d => d.FlowCode, x => x.No)
            .Map(d => d.Pwd, x => x.Password)
             .Map(d => d.FlowTitle, x => x.Title)
            .Map(d => d.FlowPubFlagName, x => "不公开")
              .Map(d => d.FlowContent, x => x.Content)
             .Map(d => d.FlowResult, x => x.ActualOpinion)
            .Map(d => d.FlowFromName, x => x.SourceChannel)
            .Map(d => d.FlowPurTypeName, x => x.AcceptType)
            .Map(d => d.FlowConTypeName, x => x.HotspotName)
            .Map(d => d.FlowAddDate, x => x.CreationTime)
            .Map(d => d.FlowEndDate, x => x.ActualHandleTime)
            .Map(d => d.FlowBMID, x => x.ActualHandleOrgCode)
            .Map(d => d.FlowBMName, x => x.ActualHandleOrgName)
            .Map(d => d.FlowLKName, x => x.FromName)
            .Map(d => d.FlowRSFlagName, x => x.Status < EOrderStatus.Filed ? "办理中" : "办理完成")
       ;

            //注册用户数据
            config.ForType<UserModelDto, WebUserRegister>()
            .Map(d => d.WebUserName, x => x.name)
            .Map(d => d.WebLoginName, x => x.username)
            .Map(d => d.PhoneNum, x => x.employeeMobile)
            .Map(d => d.IDCard, x => x.idNumber)
            .Map(d => d.Address, x => x.address)
            .Map(d => d.Gender, x => x.sex)
            ;

            //统一认证数据
            config.ForType<UserModelDto, WebUserAuth>()
            .Map(d => d.DataId, x => x.id)
            .Map(d => d.Type, x => x.type)
            .Map(d => d.Address, x => x.address)
            .Map(d => d.Birth, x => x.birth)
            .Map(d => d.DocumentType, x => x.document_type)
            .Map(d => d.IdNumber, x => x.idNumber)
            .Map(d => d.Nationality, x => x.nationality)
            .Map(d => d.Name, x => x.name)
            .Map(d => d.Sex, x => x.sex)
            .Map(d => d.DisplayName, x => x.displayName)
            .Map(d => d.Username, x => x.username)
            .Map(d => d.EmployeeMobile, x => x.employeeMobile)
            ;

            //门户网站写信
            config.ForType<WebFlowAcceptDto, AddOrderDto>()
            .Map(d => d.FromName, x => x.LKName)
            .Map(d => d.FromGender, x => x.Sex == "男" ? EGender.Male : x.Sex == "女" ? EGender.Female : EGender.Unknown)
            .Map(d => d.IsSecret, x => x.IsSecret == "1" ? true : false)
            .Map(d => d.LicenceNo, x => x.IDCard)
            .Map(d => d.Contact, x => x.Mobile)
             .Map(d => d.Street, x => x.Address)
            .Map(d => d.Title, x => x.Title)
            .Map(d => d.Content, x => x.Content)
            .Map(d => d.AcceptType, x => x.PurTypeName)
            .Map(d => d.AcceptTypeCode, x => x.PurTypeID)
            ;

            //回访部门
            config.ForType<OrderVisitDetail, WaitVisitListDataDto>()
            .Map(d => d.Id, x => x.Id)
            .Map(d => d.VisitId, x => x.VisitId)
            .Map(d => d.VisitOrgCode, x => x.VisitOrgCode)
            .Map(d => d.VisitOrgName, x => x.VisitOrgName)
            .Map(d => d.VisitContent, x => x.VisitContent)
            .Map(d => d.SatisfactionCode, x => x.OrgProcessingResults != null ? x.OrgProcessingResults.Value : "")
            ;

            #endregion
        }
    }
}
