using AutoMapper;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Domain.Share;

namespace IRaCIS.Core.Application.AutoMapper
{
    /// <summary>
    /// 映射配置
    /// </summary>
    public partial class SiteSurveyConfig : Profile
    {
        public SiteSurveyConfig()
        {
            //编辑
            CreateMap<TrialSiteSurvey, TrialSiteSurveyAddOrEdit>().ReverseMap();

            CreateMap<TrialSiteEquipmentSurveyAddOrEdit, TrialSiteEquipmentSurvey>().ReverseMap();

            CreateMap<TrialSiteUserSurveyAddOrEdit, TrialSiteUserSurvey>().ReverseMap();

            CreateMap<LoginDto, TrialSiteSurvey>().ForMember(d => d.Email, t => t.MapFrom(t => t.EmailOrPhone));


            //列表
            CreateMap<TrialSiteEquipmentSurvey, TrialSiteEquipmentSurveyView>()
                .ForMember(t=>t.EquipmentType,u=>u.MapFrom(d=>d.EquipmentType.Value));



            CreateMap<TrialSiteSurvey, TrialSiteSurveyView>()
                 .ForMember(d => d.TrialSiteAliasName, u => u.MapFrom(s => s.TrialSite.TrialSiteAliasName))
                  .ForMember(d => d.SiteName, u => u.MapFrom(s => s.Site.SiteName))
                   .ForMember(d => d.TrialSiteCode, u => u.MapFrom(s => s.TrialSite.TrialSiteCode));

            CreateMap<TrialSiteUserSurvey, TrialSiteUserSurveyView>()
              .ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value))
             .ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName));


            CreateMap<Trial, TrialSurveyInitInfo>()
                .ForMember(d => d.Sponsor, u => u.MapFrom(s => s.Sponsor.SponsorName))
                .ForMember(d => d.IndicationType, u => u.MapFrom(s => s.IndicationType.Value))
                .ForMember(d => d.TrialSiteSelectList, u => u.MapFrom(s => s.TrialSiteList))
                .ForMember(d => d.TrialId, u => u.MapFrom(s => s.Id));

            CreateMap<TrialSite, TrialSiteForSelect>()
                .ForMember(t=>t.IsHaveSiteSurveyRecord,u=>u.MapFrom(t=>t.TrialSiteSurveyList.Any()));

            CreateMap<TrialSiteSurvey, LoginReturnDTO>()
                .ForMember(d => d.TrialSiteSurvey, u => u.MapFrom(s => s))
                .ForMember(d => d.TrialInfo, u => u.MapFrom(s => s.Trial))
            .ForMember(d => d.TrialSiteUserSurveyList, u => u.MapFrom(s => s.TrialSiteUserSurveyList));




            CreateMap<TrialSiteUserSurvey, User>();

            CreateMap<TrialSiteUserSurveyView, User>();


            CreateMap<User, UserInfoBasic>().ForMember(d => d.RealName, u => u.MapFrom(s => s.LastName + " / " + s.FirstName));



            CreateMap<TrialSiteUserSurvey, TrialSiteUserSurveyAllDTO>()
                .ForMember(t=>t.TrialSiteSurvey,u=>u.MapFrom(c=>c.TrialSiteSurvey))
                 .ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value))
             .ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName));

            


        }
    }
}