using Furion;
using Mapster;
using Nirvana.Common;
using YBDevice.Entity;
using YBDevice.Entity.ViewModel;
using YBDevice.NApi.Application.MeasureInfo;
using YBDevice.NApi.Application.ThirdOpen;
using YBDevice.NApi.Application.UserInfo;

namespace YBDevice.Application
{
    public class Mapper : IRegister
    {
        private static string APICDNURL = App.Configuration["APICDNURL"];//API图片CDN地址
        /// <summary>
        /// 自定义映射
        /// </summary>
        /// <param name="config"></param>
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<BodyMeasureHisList, BodyMeasureHisListDto>()
               .Map(dest => dest.time, src => src.time.ToYearDateTime())
               .Map(dest => dest.age, src => $"{src.age}岁")
               ;
            //用户使用过的设备类型
            config.ForType<YB_DeviceTypeExt, UserDevTypeS2CDto>()
               .Map(dest => dest.HeadImg, src => $"{APICDNURL}{src.HeadImg}")
               ;
            //儿童成长曲线
            config.ForType<YB_FamilyReportData, ChildGrowthModel>()
                .Map(dest => dest.Time, src => src.CreateTime.ToString("yyyy/MM"))
                .Map(dest => dest.Weight, src => src.Weight.ToDecimal(1))
                 .Map(dest => dest.Header, src => src.Head.ToDecimal(1))
               ;
            //记录对比
            config.ForType<UserMeasureModel, ResultDiffItemS2SDto>()
                .Map(dest => dest.weight, src => src.weight.ToDecimal(1))
                .Map(dest => dest.fat_r, src => src.fat_r.ToDecimal(1))
                .Map(dest => dest.muscle, src => src.muscle.ToDecimal(1))
                .Map(dest => dest.water, src => src.water.ToDecimal(1))
                .Map(dest => dest.bone, src => src.bone.ToDecimal(1))
                .Map(dest => dest.fat_w, src => src.fat_w.ToDecimal(1))
                .Map(dest => dest.visceral, src => src.visceral.ToDecimal(1))
                .Map(dest => dest.protein, src => src.protein.ToDecimal(1))
                .Map(dest => dest.cmi, src => src.cmi.ToDecimal(1))
                .Map(dest => dest.sfr, src => src.sfr.ToDecimal(1))
                .Map(dest => dest.muscleval, src => src.muscleval.ToDecimal(1))
                .Map(dest => dest.proteinval, src => src.proteinval.ToDecimal(1))
                .Map(dest => dest.lbm, src => src.lbm.ToDecimal(1))
                .Map(dest => dest.weight, src => src.weight.ToDecimal(1))
               ;
            config.ForType<YB_MiniProgramHistory, WxOpenUpgradeS2CDto>()
               .Map(dest => dest.Version, src => src.UserVersion)
               .Map(dest => dest.Desc, src => src.UserDesc)
              ;
            config.ForType<YB_ChildBodyDetail, ChildBodySubmitResult>()
               .Map(dest => dest.BodyType, src => EnumHelper.GetEnumTitle(src.Type))
              ;
        }
    }
}
