using Mapster;
using Nirvana.Common;
using YBDevice.Application.DeviceInfo;
using YBDevice.Application.OfficeialInfo;
using YBDevice.Application.OrderInfo;
using YBDevice.Entity;

namespace YBDevice.Application
{
    public class Mapper : IRegister
    {
        /// <summary>
        /// 自定义映射
        /// </summary>
        /// <param name="config"></param>
        public void Register(TypeAdapterConfig config)
        {
            //config.ForType<Entity, Dto>()
            //   .Map(dest => dest.FullName, src => src.FirstName + src.LastName)
            //   .Map(dest => dest.IdCard, src => src.IdCard.Replace("1234", "****"));
            config.ForType<YB_DayReport, ReportChartDto>()
               .Map(dest => dest.Time, src => src.RecordTime.ToYearDate())
               ;
            config.ForType<OrderList, OrderDto>()
                .Map(dest => dest.time, src => $"{(src.StartTime.HasValue ? src.StartTime.Value.ToString("yyyy/MM/dd") : "")}-{(src.EndTime.HasValue ? src.EndTime.Value.ToString("yyyy/MM/dd") : "")}")
                ;
            //订阅消息模板
            config.ForType<YB_MiniProgramSubscribeMessageTpl, MiniSubscribeTplS2CDto>();
            //订阅消息模板
            config.ForType<DeviceAllocListS2SDto, DeviceAllocListSCDto>()
                 .Map(dest => dest.OpName, src => OpName(src.Type))
               ;
        }
        /// <summary>
        /// 分配记录操作名称
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private string OpName(DeviceAllocType type)
            => type switch
            {
                DeviceAllocType.OUT => "出货",
                DeviceAllocType.ALLOC => "分配=>",
                DeviceAllocType.RETURN => "回收",
                DeviceAllocType.ACTIVE => "激活",
                _ => ""
            };
    }
}
