using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using DocuMed.Domain.Dtos.LargDtos;
using DocuMed.Domain.Dtos.SmallDtos;
using DocuMed.Domain.Entities.City;
using DocuMed.Domain.Entities.MedicalHistory;
using DocuMed.Domain.Entities.User;
using Mapster.Models;

namespace DocuMed.Domain.Mappers
{
    public static partial class MedicalHistoryMapper
    {
        public static MedicalHistory AdaptToMedicalHistory(this MedicalHistorySDto p1)
        {
            return p1 == null ? null : new MedicalHistory()
            {
                ChiefComplaint = p1.ChiefComplaint,
                SectionId = p1.SectionId,
                Section = new Section()
                {
                    Name = p1.SectionName,
                    Id = p1.SectionId
                },
                FirstName = p1.FirstName,
                LastName = p1.LastName,
                FatherName = p1.FatherName,
                NationalId = p1.NationalId,
                Age = p1.Age,
                BirthDate = p1.BirthDate,
                PresentIllnessDetail = p1.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p1.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p1.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p1.FamilyHistoryDetail,
                AllergyDetail = p1.AllergyDetail,
                DrugHistoryDetail = p1.DrugHistoryDetail,
                AddictionHistoryDetail = p1.AddictionHistoryDetail,
                SystemReviewDetail = p1.SystemReviewDetail,
                VitalSignDetail = p1.VitalSignDetail,
                SystolicBloodPressure = p1.SystolicBloodPressure,
                DiastolicBloodPressure = p1.DiastolicBloodPressure,
                PulseRate = p1.PulseRate,
                SPO2 = p1.SPO2,
                Temperature = p1.Temperature,
                ApplicationUserId = p1.ApplicationUserId,
                ApplicationUser = new ApplicationUser() {Id = p1.ApplicationUserId},
                Id = p1.Id
            };
        }
        public static MedicalHistory AdaptTo(this MedicalHistorySDto p2, MedicalHistory p3)
        {
            if (p2 == null)
            {
                return null;
            }
            MedicalHistory result = p3 ?? new MedicalHistory();
            
            result.ChiefComplaint = p2.ChiefComplaint;
            result.SectionId = p2.SectionId;
            result.Section = funcMain1(new Never(), result.Section, p2);
            result.FirstName = p2.FirstName;
            result.LastName = p2.LastName;
            result.FatherName = p2.FatherName;
            result.NationalId = p2.NationalId;
            result.Age = p2.Age;
            result.BirthDate = p2.BirthDate;
            result.PresentIllnessDetail = p2.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p2.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p2.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p2.FamilyHistoryDetail;
            result.AllergyDetail = p2.AllergyDetail;
            result.DrugHistoryDetail = p2.DrugHistoryDetail;
            result.AddictionHistoryDetail = p2.AddictionHistoryDetail;
            result.SystemReviewDetail = p2.SystemReviewDetail;
            result.VitalSignDetail = p2.VitalSignDetail;
            result.SystolicBloodPressure = p2.SystolicBloodPressure;
            result.DiastolicBloodPressure = p2.DiastolicBloodPressure;
            result.PulseRate = p2.PulseRate;
            result.SPO2 = p2.SPO2;
            result.Temperature = p2.Temperature;
            result.ApplicationUserId = p2.ApplicationUserId;
            result.ApplicationUser = funcMain2(new Never(), result.ApplicationUser, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistorySDto, MedicalHistory>> ProjectToMedicalHistory => p8 => new MedicalHistory()
        {
            ChiefComplaint = p8.ChiefComplaint,
            SectionId = p8.SectionId,
            Section = new Section()
            {
                Name = p8.SectionName,
                Id = p8.SectionId
            },
            FirstName = p8.FirstName,
            LastName = p8.LastName,
            FatherName = p8.FatherName,
            NationalId = p8.NationalId,
            Age = p8.Age,
            BirthDate = p8.BirthDate,
            PresentIllnessDetail = p8.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p8.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p8.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p8.FamilyHistoryDetail,
            AllergyDetail = p8.AllergyDetail,
            DrugHistoryDetail = p8.DrugHistoryDetail,
            AddictionHistoryDetail = p8.AddictionHistoryDetail,
            SystemReviewDetail = p8.SystemReviewDetail,
            VitalSignDetail = p8.VitalSignDetail,
            SystolicBloodPressure = p8.SystolicBloodPressure,
            DiastolicBloodPressure = p8.DiastolicBloodPressure,
            PulseRate = p8.PulseRate,
            SPO2 = p8.SPO2,
            Temperature = p8.Temperature,
            ApplicationUserId = p8.ApplicationUserId,
            ApplicationUser = new ApplicationUser() {Id = p8.ApplicationUserId},
            Id = p8.Id
        };
        public static MedicalHistorySDto AdaptToSDto(this MedicalHistory p9)
        {
            return p9 == null ? null : new MedicalHistorySDto()
            {
                ChiefComplaint = p9.ChiefComplaint,
                SectionId = p9.SectionId,
                SectionName = p9.Section != null ? p9.Section.Name : string.Empty,
                FirstName = p9.FirstName,
                LastName = p9.LastName,
                FatherName = p9.FatherName,
                NationalId = p9.NationalId,
                Age = p9.Age,
                BirthDate = p9.BirthDate,
                PresentIllnessDetail = p9.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p9.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p9.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p9.FamilyHistoryDetail,
                AllergyDetail = p9.AllergyDetail,
                DrugHistoryDetail = p9.DrugHistoryDetail,
                AddictionHistoryDetail = p9.AddictionHistoryDetail,
                SystemReviewDetail = p9.SystemReviewDetail,
                VitalSignDetail = p9.VitalSignDetail,
                SystolicBloodPressure = p9.SystolicBloodPressure,
                DiastolicBloodPressure = p9.DiastolicBloodPressure,
                PulseRate = p9.PulseRate,
                SPO2 = p9.SPO2,
                Temperature = p9.Temperature,
                ApplicationUserId = p9.ApplicationUserId,
                Id = p9.Id
            };
        }
        public static MedicalHistorySDto AdaptTo(this MedicalHistory p10, MedicalHistorySDto p11)
        {
            if (p10 == null)
            {
                return null;
            }
            MedicalHistorySDto result = p11 ?? new MedicalHistorySDto();
            
            result.ChiefComplaint = p10.ChiefComplaint;
            result.SectionId = p10.SectionId;
            result.SectionName = p10.Section != null ? p10.Section.Name : string.Empty;
            result.FirstName = p10.FirstName;
            result.LastName = p10.LastName;
            result.FatherName = p10.FatherName;
            result.NationalId = p10.NationalId;
            result.Age = p10.Age;
            result.BirthDate = p10.BirthDate;
            result.PresentIllnessDetail = p10.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p10.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p10.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p10.FamilyHistoryDetail;
            result.AllergyDetail = p10.AllergyDetail;
            result.DrugHistoryDetail = p10.DrugHistoryDetail;
            result.AddictionHistoryDetail = p10.AddictionHistoryDetail;
            result.SystemReviewDetail = p10.SystemReviewDetail;
            result.VitalSignDetail = p10.VitalSignDetail;
            result.SystolicBloodPressure = p10.SystolicBloodPressure;
            result.DiastolicBloodPressure = p10.DiastolicBloodPressure;
            result.PulseRate = p10.PulseRate;
            result.SPO2 = p10.SPO2;
            result.Temperature = p10.Temperature;
            result.ApplicationUserId = p10.ApplicationUserId;
            result.Id = p10.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistory, MedicalHistorySDto>> ProjectToSDto => p12 => new MedicalHistorySDto()
        {
            ChiefComplaint = p12.ChiefComplaint,
            SectionId = p12.SectionId,
            SectionName = p12.Section != null ? p12.Section.Name : string.Empty,
            FirstName = p12.FirstName,
            LastName = p12.LastName,
            FatherName = p12.FatherName,
            NationalId = p12.NationalId,
            Age = p12.Age,
            BirthDate = p12.BirthDate,
            PresentIllnessDetail = p12.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p12.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p12.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p12.FamilyHistoryDetail,
            AllergyDetail = p12.AllergyDetail,
            DrugHistoryDetail = p12.DrugHistoryDetail,
            AddictionHistoryDetail = p12.AddictionHistoryDetail,
            SystemReviewDetail = p12.SystemReviewDetail,
            VitalSignDetail = p12.VitalSignDetail,
            SystolicBloodPressure = p12.SystolicBloodPressure,
            DiastolicBloodPressure = p12.DiastolicBloodPressure,
            PulseRate = p12.PulseRate,
            SPO2 = p12.SPO2,
            Temperature = p12.Temperature,
            ApplicationUserId = p12.ApplicationUserId,
            Id = p12.Id
        };
        public static MedicalHistory AdaptToMedicalHistory(this MedicalHistoryLDto p13)
        {
            return p13 == null ? null : new MedicalHistory()
            {
                ChiefComplaint = p13.ChiefComplaint,
                SectionId = p13.SectionId,
                FirstName = p13.FirstName,
                LastName = p13.LastName,
                FatherName = p13.FatherName,
                NationalId = p13.NationalId,
                Age = p13.Age,
                BirthDate = p13.BirthDate,
                PresentIllnessDetail = p13.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p13.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p13.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p13.FamilyHistoryDetail,
                AllergyDetail = p13.AllergyDetail,
                DrugHistoryDetail = p13.DrugHistoryDetail,
                AddictionHistoryDetail = p13.AddictionHistoryDetail,
                SystemReviewDetail = p13.SystemReviewDetail,
                VitalSignDetail = p13.VitalSignDetail,
                SystolicBloodPressure = p13.SystolicBloodPressure,
                DiastolicBloodPressure = p13.DiastolicBloodPressure,
                PulseRate = p13.PulseRate,
                SPO2 = p13.SPO2,
                Temperature = p13.Temperature,
                ApplicationUserId = p13.ApplicationUserId,
                Answers = funcMain3(p13.Answers),
                Id = p13.Id
            };
        }
        public static MedicalHistory AdaptTo(this MedicalHistoryLDto p15, MedicalHistory p16)
        {
            if (p15 == null)
            {
                return null;
            }
            MedicalHistory result = p16 ?? new MedicalHistory();
            
            result.ChiefComplaint = p15.ChiefComplaint;
            result.SectionId = p15.SectionId;
            result.FirstName = p15.FirstName;
            result.LastName = p15.LastName;
            result.FatherName = p15.FatherName;
            result.NationalId = p15.NationalId;
            result.Age = p15.Age;
            result.BirthDate = p15.BirthDate;
            result.PresentIllnessDetail = p15.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p15.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p15.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p15.FamilyHistoryDetail;
            result.AllergyDetail = p15.AllergyDetail;
            result.DrugHistoryDetail = p15.DrugHistoryDetail;
            result.AddictionHistoryDetail = p15.AddictionHistoryDetail;
            result.SystemReviewDetail = p15.SystemReviewDetail;
            result.VitalSignDetail = p15.VitalSignDetail;
            result.SystolicBloodPressure = p15.SystolicBloodPressure;
            result.DiastolicBloodPressure = p15.DiastolicBloodPressure;
            result.PulseRate = p15.PulseRate;
            result.SPO2 = p15.SPO2;
            result.Temperature = p15.Temperature;
            result.ApplicationUserId = p15.ApplicationUserId;
            result.Answers = funcMain4(p15.Answers, result.Answers);
            result.Id = p15.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryLDto, MedicalHistory>> ProjectLDtoToMedicalHistory => p19 => new MedicalHistory()
        {
            ChiefComplaint = p19.ChiefComplaint,
            SectionId = p19.SectionId,
            FirstName = p19.FirstName,
            LastName = p19.LastName,
            FatherName = p19.FatherName,
            NationalId = p19.NationalId,
            Age = p19.Age,
            BirthDate = p19.BirthDate,
            PresentIllnessDetail = p19.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p19.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p19.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p19.FamilyHistoryDetail,
            AllergyDetail = p19.AllergyDetail,
            DrugHistoryDetail = p19.DrugHistoryDetail,
            AddictionHistoryDetail = p19.AddictionHistoryDetail,
            SystemReviewDetail = p19.SystemReviewDetail,
            VitalSignDetail = p19.VitalSignDetail,
            SystolicBloodPressure = p19.SystolicBloodPressure,
            DiastolicBloodPressure = p19.DiastolicBloodPressure,
            PulseRate = p19.PulseRate,
            SPO2 = p19.SPO2,
            Temperature = p19.Temperature,
            ApplicationUserId = p19.ApplicationUserId,
            Answers = p19.Answers.Select<MedicalHistoryAnswerSDto, MedicalHistoryAnswer>(p20 => new MedicalHistoryAnswer()
            {
                Answer = p20.Answer,
                Question = p20.Question,
                Part = p20.Part,
                QuestionType = p20.QuestionType,
                MedicalHistoryId = p20.MedicalHistoryId,
                Id = p20.Id
            }).ToList<MedicalHistoryAnswer>(),
            Id = p19.Id
        };
        public static MedicalHistoryLDto AdaptToLDto(this MedicalHistory p21)
        {
            return p21 == null ? null : new MedicalHistoryLDto()
            {
                ChiefComplaint = p21.ChiefComplaint,
                SectionId = p21.SectionId,
                FirstName = p21.FirstName,
                LastName = p21.LastName,
                FatherName = p21.FatherName,
                NationalId = p21.NationalId,
                Age = p21.Age,
                BirthDate = p21.BirthDate,
                PresentIllnessDetail = p21.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p21.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p21.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p21.FamilyHistoryDetail,
                AllergyDetail = p21.AllergyDetail,
                DrugHistoryDetail = p21.DrugHistoryDetail,
                AddictionHistoryDetail = p21.AddictionHistoryDetail,
                SystemReviewDetail = p21.SystemReviewDetail,
                VitalSignDetail = p21.VitalSignDetail,
                SystolicBloodPressure = p21.SystolicBloodPressure,
                DiastolicBloodPressure = p21.DiastolicBloodPressure,
                PulseRate = p21.PulseRate,
                SPO2 = p21.SPO2,
                Temperature = p21.Temperature,
                ApplicationUserId = p21.ApplicationUserId,
                Answers = funcMain5(p21.Answers),
                Id = p21.Id
            };
        }
        public static MedicalHistoryLDto AdaptTo(this MedicalHistory p23, MedicalHistoryLDto p24)
        {
            if (p23 == null)
            {
                return null;
            }
            MedicalHistoryLDto result = p24 ?? new MedicalHistoryLDto();
            
            result.ChiefComplaint = p23.ChiefComplaint;
            result.SectionId = p23.SectionId;
            result.FirstName = p23.FirstName;
            result.LastName = p23.LastName;
            result.FatherName = p23.FatherName;
            result.NationalId = p23.NationalId;
            result.Age = p23.Age;
            result.BirthDate = p23.BirthDate;
            result.PresentIllnessDetail = p23.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p23.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p23.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p23.FamilyHistoryDetail;
            result.AllergyDetail = p23.AllergyDetail;
            result.DrugHistoryDetail = p23.DrugHistoryDetail;
            result.AddictionHistoryDetail = p23.AddictionHistoryDetail;
            result.SystemReviewDetail = p23.SystemReviewDetail;
            result.VitalSignDetail = p23.VitalSignDetail;
            result.SystolicBloodPressure = p23.SystolicBloodPressure;
            result.DiastolicBloodPressure = p23.DiastolicBloodPressure;
            result.PulseRate = p23.PulseRate;
            result.SPO2 = p23.SPO2;
            result.Temperature = p23.Temperature;
            result.ApplicationUserId = p23.ApplicationUserId;
            result.Answers = funcMain6(p23.Answers, result.Answers);
            result.Id = p23.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistory, MedicalHistoryLDto>> ProjectToLDto => p27 => new MedicalHistoryLDto()
        {
            ChiefComplaint = p27.ChiefComplaint,
            SectionId = p27.SectionId,
            FirstName = p27.FirstName,
            LastName = p27.LastName,
            FatherName = p27.FatherName,
            NationalId = p27.NationalId,
            Age = p27.Age,
            BirthDate = p27.BirthDate,
            PresentIllnessDetail = p27.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p27.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p27.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p27.FamilyHistoryDetail,
            AllergyDetail = p27.AllergyDetail,
            DrugHistoryDetail = p27.DrugHistoryDetail,
            AddictionHistoryDetail = p27.AddictionHistoryDetail,
            SystemReviewDetail = p27.SystemReviewDetail,
            VitalSignDetail = p27.VitalSignDetail,
            SystolicBloodPressure = p27.SystolicBloodPressure,
            DiastolicBloodPressure = p27.DiastolicBloodPressure,
            PulseRate = p27.PulseRate,
            SPO2 = p27.SPO2,
            Temperature = p27.Temperature,
            ApplicationUserId = p27.ApplicationUserId,
            Answers = p27.Answers.Select<MedicalHistoryAnswer, MedicalHistoryAnswerSDto>(p28 => new MedicalHistoryAnswerSDto()
            {
                Answer = p28.Answer,
                Question = p28.Question,
                Part = p28.Part,
                QuestionType = p28.QuestionType,
                MedicalHistoryId = p28.MedicalHistoryId,
                Id = p28.Id
            }).ToList<MedicalHistoryAnswerSDto>(),
            Id = p27.Id
        };
        
        private static Section funcMain1(Never p4, Section p5, MedicalHistorySDto p2)
        {
            Section result = p5 ?? new Section();
            
            result.Name = p2.SectionName;
            result.Id = p2.SectionId;
            return result;
            
        }
        
        private static ApplicationUser funcMain2(Never p6, ApplicationUser p7, MedicalHistorySDto p2)
        {
            ApplicationUser result = p7 ?? new ApplicationUser();
            
            result.Id = p2.ApplicationUserId;
            return result;
            
        }
        
        private static List<MedicalHistoryAnswer> funcMain3(List<MedicalHistoryAnswerSDto> p14)
        {
            if (p14 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswer> result = new List<MedicalHistoryAnswer>(p14.Count);
            
            int i = 0;
            int len = p14.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswerSDto item = p14[i];
                result.Add(item == null ? null : new MedicalHistoryAnswer()
                {
                    Answer = item.Answer,
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryId = item.MedicalHistoryId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryAnswer> funcMain4(List<MedicalHistoryAnswerSDto> p17, List<MedicalHistoryAnswer> p18)
        {
            if (p17 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswer> result = new List<MedicalHistoryAnswer>(p17.Count);
            
            int i = 0;
            int len = p17.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswerSDto item = p17[i];
                result.Add(item == null ? null : new MedicalHistoryAnswer()
                {
                    Answer = item.Answer,
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryId = item.MedicalHistoryId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryAnswerSDto> funcMain5(List<MedicalHistoryAnswer> p22)
        {
            if (p22 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswerSDto> result = new List<MedicalHistoryAnswerSDto>(p22.Count);
            
            int i = 0;
            int len = p22.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswer item = p22[i];
                result.Add(item == null ? null : new MedicalHistoryAnswerSDto()
                {
                    Answer = item.Answer,
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryId = item.MedicalHistoryId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryAnswerSDto> funcMain6(List<MedicalHistoryAnswer> p25, List<MedicalHistoryAnswerSDto> p26)
        {
            if (p25 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswerSDto> result = new List<MedicalHistoryAnswerSDto>(p25.Count);
            
            int i = 0;
            int len = p25.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswer item = p25[i];
                result.Add(item == null ? null : new MedicalHistoryAnswerSDto()
                {
                    Answer = item.Answer,
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryId = item.MedicalHistoryId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}