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<TrialSiteUser, TrialSiteUserSurvey>()
                 .ForMember(d => d.Id, u => u.Ignore())
                 .ForMember(d => d.Phone, u => u.MapFrom(c => c.User.Phone))
                 .ForMember(d => d.Email, u => u.MapFrom(c => c.User.EMail))
                 .ForMember(d => d.OrganizationName, u => u.MapFrom(c => c.User.OrganizationName))
                 .ForMember(d => d.UserTypeId, u => u.MapFrom(c => c.User.UserTypeId))
                 .ForMember(d => d.IsHistoryUser, u => u.MapFrom(c => true))
                 .ForMember(d => d.IsHistoryUserOriginDeleted, u => u.MapFrom(c => c.IsDeleted))
                 .ForMember(d => d.IsHistoryUserDeleted, u => u.MapFrom(c => c.IsDeleted))
                 .ForMember(d => d.FirstName, u => u.MapFrom(c => c.User.FirstName))
                 .ForMember(d => d.LastName, u => u.MapFrom(c => c.User.LastName))
                 .ForMember(d => d.IsGenerateAccount, u => u.MapFrom(c => true))
                 .ForMember(d => d.IsGenerateSuccess, u => u.MapFrom(c => true))
                 .ForMember(d => d.SystemUserId, u => u.MapFrom(c => c.UserId))
                 .ForMember(d => d.IsJoin, u => u.MapFrom(c => !c.IsDeleted));



            //列表
            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<TrialSiteSurvey, TrialSiteSurveySelectView>();

            var isEn_Us = false;
            CreateMap<TrialSiteUserSurvey, TrialSiteUserSurveyView>()
              .ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName))
               .ForMember(d => d.UserTypeEnum, u => u.MapFrom(s => s.UserTypeRole.UserTypeEnum));


            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<SiteSurveyUserImportDto, User>()
                .ForMember(d => d.EMail, u => u.MapFrom(s => s.Email));
            

            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(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName))
             .ForMember(d => d.UserTypeEnum, u => u.MapFrom(s => s.UserTypeRole.UserTypeEnum));

            


        }
    }
}