using AutoMapper;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Service.Reading.Dto;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Models;


namespace IRaCIS.Core.Application.Service
{
    public class ReadingConfig : Profile
    {
        public ReadingConfig()
        {
            CreateMap<ReadingPeriodSetAddOrEdit, ReadingPeriodSet>();


            CreateMap<ReadingPeriodSet, ReadingPeriodSetView>()
                .ForMember(d => d.SubjectVisitName, u => u.MapFrom(s => s.VisitStage==null?string.Empty: s.VisitStage.VisitName))
                .ForMember(d => d.SiteIds, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.SiteId)))
                .ForMember(d => d.SiteCodes, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.TrialSite.TrialSiteCode)))
                .ForMember(d => d.PlanCount, u => u.MapFrom(s => s.ReadingPeriodPlanList.Count));

            //CreateMap<ReadingClinicalDataView, GetReadingClinicalDataListOutDto>();
           // CreateMap<ReadingClinicalData, GetReadingClinicalDataListOutDto>()
           //.ForMember(d => d.ClinicalDataLevel, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalDataLevel))
           //.ForMember(d => d.ClinicalDataLevelName, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalDataSetName))
           //.ForMember(d => d.ClinicalUploadType, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalUploadType));
           //.ForMember(d => d.FileCount, u => u.MapFrom(s => s.ReadingClinicalDataPDFList.Count()));

            CreateMap<ReadingClinicalDataPDF, GetReadingClinicalDataPDFListOutDto>();

            //.ForMember(d => d.SiteNames, u => u.MapFrom(s => s.ReadingPeriodSites.SelectMany(x => x.Site.SiteName).ToList()));

            CreateMap<ReadingClinicalData, AddOrUpdateReadingClinicalDataDto>().ReverseMap();

            CreateMap<ReadingClinicalDataPDF, AddOrUpdateReadingClinicalDataPDFDto>().ReverseMap();

            CreateMap<ClinicalDataTrialSet, ClinicalDataTrialSetAddOrEdit>().ReverseMap();

            CreateMap<ClinicalDataSystemSet, ClinicalDataSystemSetAddOrEdit>().ReverseMap();

            CreateMap<ClinicalDataTrialSet, ClinicalDataTrialSetView>()
                    .ForMember(d => d.IsUsed, u => u.MapFrom(s => s.ReadingClinicalDataList.Count()>0));
            CreateMap<ClinicalDataSystemSet, ClinicalDataSystemSetView>();

            CreateMap<PreviousPDF, PreviousPDFAddOrEdit>().ReverseMap();

            CreateMap<PreviousPDF, PreviousPDFView>();

            CreateMap<ReadModuleAddOrEdit, ReadModule>();

            #region 阅片问题


          
            CreateMap<ReadingCriterionPageAddOrEdit, ReadingCriterionPage>();
            CreateMap<AddOrUpdateReadingQuestionCriterionSystemInDto, ReadingQuestionCriterionSystem>();
            CreateMap<ReadingQuestionCriterionSystem, ReadingQuestionCriterionSystemView>()
                  .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionSystemList.Count()))
                   .ForMember(d => d.IsEnable, u => u.MapFrom(s => s.Dictionary.IsEnable))
                   .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)); 


            CreateMap<AddOrUpdateReadingQuestionSystemInDto, ReadingQuestionSystem>();
            CreateMap<ReadingQuestionSystem, ReadingQuestionSystemView>()
           .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionSystem==null?string.Empty: s.ParentReadingQuestionSystem.QuestionName))
             .ForMember(d => d.ParentQuestionShowOrder, u => u.MapFrom(s => s.ParentReadingQuestionSystem.ShowOrder));


            CreateMap<AddOrUpdateReadingQuestionCriterionTrialInDto, ReadingQuestionCriterionTrial>();
            CreateMap<ReadingQuestionCriterionTrial, ReadingQuestionCriterionTrialView>()
                 .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionTrialList.Count())); 


            CreateMap<AddOrUpdateReadingQuestionTrialInDto, ReadingQuestionTrial>();
            CreateMap<ReadingQuestionTrial, ReadingQuestionTrialView>()
                 .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionTrial == null ? string.Empty : s.ParentReadingQuestionTrial.QuestionName))
            .ForMember(d => d.ParentQuestionShowOrder, u => u.MapFrom(s => s.ParentReadingQuestionTrial.ShowOrder));
                 #endregion

            #region IR阅片
            CreateMap<ReadingQuestionTrial, GetTrialReadingQuestionOutDto>()
                .ForMember(x=>x.ReadingQuestionTrialId, y=>y.MapFrom(z=>z.Id));

            CreateMap<VisitTask, GetReadingPastResultListOutDto>()
                  .ForMember(x => x.VisitTaskId, y => y.MapFrom(z => z.Id));
            #endregion

            #region 医学审核
            CreateMap<ReadingMedicineSystemQuestionAddOrEdit, ReadingMedicineSystemQuestion>();
            CreateMap<ReadingMedicineSystemQuestion, ReadingMedicineSystemQuestionView>();

            CreateMap<ReadingMedicineTrialQuestionAddOrEdit, ReadingMedicineTrialQuestion>();
            CreateMap<ReadingMedicineTrialQuestion, ReadingMedicineTrialQuestionView>()
                .ForMember(x=>x.ParentShowOrder,y=>y.MapFrom(n=>n.ParentQuestion.ShowOrder));

            CreateMap<ReadingMedicineTrialQuestion, GetMedicineQuestionPreviewOutDto>();


            CreateMap<TaskMedicalReview, MedicalReviewInfo>()
                .ForMember(x => x.TaskMedicalReviewId, y => y.MapFrom(n => n.Id));

            CreateMap<ReadingMedicalReviewDialog, GetMedicalReviewDialogOutDto>()
                 .ForMember(x => x.CreateUserName, y => y.MapFrom(n => n.CreateUser.UserName));
            
            #endregion


        }
    }
   
}
