using AngleSharp.Text;
using Hotline.Orders;
using Hotline.Settings;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums.Order;
using Hotline.Share.Tools;
using Hotline.Snapshot;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.Application.Mappers;
public class SnapshotMapperConfigs : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.ForType<AddSnapshotOrderInDto, OrderSnapshot>()
           .Ignore(m => m.StartWorkTime)
           .Ignore(m => m.EndWorkTime);

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

        config.ForType<SystemArea, Kv>()
            .Map(m => m.Key, n => n.Id)
            .Map(m => m.Value, n => n.AreaName);

        config.ForType< SnapshotBulletin, SnapshotBulletinDetailOutDto>()
         .Map(m => m.BulletinTypeId, n => n.SnapshotBulletinTypeId)
         .Map(m => m.BulletinTypeName, n => n.SnapshotBulletinTypeName);

        config.ForType<UpdateSnapshotBulletinInDto, SnapshotBulletin>()
            .Map(m => m.SnapshotBulletinTypeId, n => n.BulletinTypeId)
            .Map(m => m.SnapshotBulletinTypeName, n => n.BulletinTypeName);

        config.ForType<AddSnapshotBulletinInDto, SnapshotBulletin>()
            .Map(m => m.SnapshotBulletinTypeId, n => n.BulletinTypeId)
            .Map(m => m.SnapshotBulletinTypeName, n => n.BulletinTypeName);

        config.ForType<GuiderSystemInDto, CommunityInfo>()
            .Map(dest => dest.Name, src => src.OrgName)
            .Map(dest => dest.ParentCode, src => src.ParentOrgId)
            .Map(dest => dest.Id, src => src.OrgId)
            .Map(dest => dest.FullName, src => src.OrgFullName)
            .AfterMapping((dest, src) => 
            {
                src.Id = dest.OrgId;
            });

        config.ForType<AddIndustryDto, Industry>();
        config.ForType<Hotline.File.File, IndustryFileDto>()
            .Map(m => m.AdditionId, n => n.Additions);

        config.ForType<SnapshotFileInDto, File.File>()
            .Map(m => m.Additions, n => n.AdditionId);

        config.ForType<AddSnapshotOrderInDto, Order>()
            .Map(m => m.Contact, n => n.PhoneNumber)
            .Map(m => m.FromName, n => n.Name)
            .Map(m => m.FromPhone, n => n.PhoneNumber);

        config.ForType<SnapshotOrderPublish, OrderPublishDetailOutDto>()
            .Map(m => m.Title, n => n.ArrangeTitle)
            .Map(m => m.Content, n => n.ArrangeContent)
            .Map(m => m.Opinion, n => n.ArrangeOpinion);

        config.ForType<Order, OrderPublishDetailOutDto>()
            .Map(m => m.Opinion, n => n.ActualOpinion);

        config.ForType<AddBatchPractitionerInDto, Practitioner>()
            .Ignore(m => m.Gender);

        config.ForType<GuiderSystemInDto, OrderSnapshot>()
            .Map(m => m.ReplyDate, n => n.ReplyDate)
            .Map(m => m.ReplyUserName, n => n.ReplyUserName)
            .Map(m => m.ReplyBMName, n => n.ReplyBMName)
            .Map(m => m.ReplyResultType, n => n.ReplyResultType)
            .Map(m => m.IsTruth, n => n.ReplyISTrue == "1")
            .Map(m => m.IsDeal, n => n.ReplyResultType == "2")
            .Map(m => m.IsRepetition, n => n.IsRepeat == "1")
            .Map(m => m.IsDanger, n => n.IsHiddenDanger == "1")
            .Map(m => m.MemberName, n => n.MemberName)
            .Map(m => m.MemberMobile, n => n.MemberMobile)
            .Map(m => m.CommunityId, n => n.OrgId)
            .Map(m => m.CommunityName, n => n.OrgName)
            .Map(m => m.CommunityFullName, n => n.OrgFullName)
            .Map(m => m.NetworkRemark, n => n.ReplyContent);
    }
}
