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.MedicalHistory;

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,
                Section = p1.Section,
                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,
                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.Section = p2.Section;
            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.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistorySDto, MedicalHistory>> ProjectToMedicalHistory => p4 => new MedicalHistory()
        {
            ChiefComplaint = p4.ChiefComplaint,
            Section = p4.Section,
            FirstName = p4.FirstName,
            LastName = p4.LastName,
            FatherName = p4.FatherName,
            NationalId = p4.NationalId,
            Age = p4.Age,
            BirthDate = p4.BirthDate,
            PresentIllnessDetail = p4.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p4.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p4.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p4.FamilyHistoryDetail,
            AllergyDetail = p4.AllergyDetail,
            DrugHistoryDetail = p4.DrugHistoryDetail,
            AddictionHistoryDetail = p4.AddictionHistoryDetail,
            SystemReviewDetail = p4.SystemReviewDetail,
            VitalSignDetail = p4.VitalSignDetail,
            SystolicBloodPressure = p4.SystolicBloodPressure,
            DiastolicBloodPressure = p4.DiastolicBloodPressure,
            PulseRate = p4.PulseRate,
            SPO2 = p4.SPO2,
            Temperature = p4.Temperature,
            ApplicationUserId = p4.ApplicationUserId,
            Id = p4.Id
        };
        public static MedicalHistorySDto AdaptToSDto(this MedicalHistory p5)
        {
            return p5 == null ? null : new MedicalHistorySDto()
            {
                ChiefComplaint = p5.ChiefComplaint,
                Section = p5.Section,
                FirstName = p5.FirstName,
                LastName = p5.LastName,
                FatherName = p5.FatherName,
                NationalId = p5.NationalId,
                Age = p5.Age,
                BirthDate = p5.BirthDate,
                PresentIllnessDetail = p5.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p5.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p5.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p5.FamilyHistoryDetail,
                AllergyDetail = p5.AllergyDetail,
                DrugHistoryDetail = p5.DrugHistoryDetail,
                AddictionHistoryDetail = p5.AddictionHistoryDetail,
                SystemReviewDetail = p5.SystemReviewDetail,
                VitalSignDetail = p5.VitalSignDetail,
                SystolicBloodPressure = p5.SystolicBloodPressure,
                DiastolicBloodPressure = p5.DiastolicBloodPressure,
                PulseRate = p5.PulseRate,
                SPO2 = p5.SPO2,
                Temperature = p5.Temperature,
                ApplicationUserId = p5.ApplicationUserId,
                Id = p5.Id
            };
        }
        public static MedicalHistorySDto AdaptTo(this MedicalHistory p6, MedicalHistorySDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            MedicalHistorySDto result = p7 ?? new MedicalHistorySDto();
            
            result.ChiefComplaint = p6.ChiefComplaint;
            result.Section = p6.Section;
            result.FirstName = p6.FirstName;
            result.LastName = p6.LastName;
            result.FatherName = p6.FatherName;
            result.NationalId = p6.NationalId;
            result.Age = p6.Age;
            result.BirthDate = p6.BirthDate;
            result.PresentIllnessDetail = p6.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p6.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p6.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p6.FamilyHistoryDetail;
            result.AllergyDetail = p6.AllergyDetail;
            result.DrugHistoryDetail = p6.DrugHistoryDetail;
            result.AddictionHistoryDetail = p6.AddictionHistoryDetail;
            result.SystemReviewDetail = p6.SystemReviewDetail;
            result.VitalSignDetail = p6.VitalSignDetail;
            result.SystolicBloodPressure = p6.SystolicBloodPressure;
            result.DiastolicBloodPressure = p6.DiastolicBloodPressure;
            result.PulseRate = p6.PulseRate;
            result.SPO2 = p6.SPO2;
            result.Temperature = p6.Temperature;
            result.ApplicationUserId = p6.ApplicationUserId;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistory, MedicalHistorySDto>> ProjectToSDto => p8 => new MedicalHistorySDto()
        {
            ChiefComplaint = p8.ChiefComplaint,
            Section = p8.Section,
            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,
            Id = p8.Id
        };
        public static MedicalHistory AdaptToMedicalHistory(this MedicalHistoryLDto p9)
        {
            return p9 == null ? null : new MedicalHistory()
            {
                ChiefComplaint = p9.ChiefComplaint,
                Section = p9.Section,
                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,
                Answers = funcMain1(p9.Answers),
                Id = p9.Id
            };
        }
        public static MedicalHistory AdaptTo(this MedicalHistoryLDto p11, MedicalHistory p12)
        {
            if (p11 == null)
            {
                return null;
            }
            MedicalHistory result = p12 ?? new MedicalHistory();
            
            result.ChiefComplaint = p11.ChiefComplaint;
            result.Section = p11.Section;
            result.FirstName = p11.FirstName;
            result.LastName = p11.LastName;
            result.FatherName = p11.FatherName;
            result.NationalId = p11.NationalId;
            result.Age = p11.Age;
            result.BirthDate = p11.BirthDate;
            result.PresentIllnessDetail = p11.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p11.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p11.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p11.FamilyHistoryDetail;
            result.AllergyDetail = p11.AllergyDetail;
            result.DrugHistoryDetail = p11.DrugHistoryDetail;
            result.AddictionHistoryDetail = p11.AddictionHistoryDetail;
            result.SystemReviewDetail = p11.SystemReviewDetail;
            result.VitalSignDetail = p11.VitalSignDetail;
            result.SystolicBloodPressure = p11.SystolicBloodPressure;
            result.DiastolicBloodPressure = p11.DiastolicBloodPressure;
            result.PulseRate = p11.PulseRate;
            result.SPO2 = p11.SPO2;
            result.Temperature = p11.Temperature;
            result.ApplicationUserId = p11.ApplicationUserId;
            result.Answers = funcMain2(p11.Answers, result.Answers);
            result.Id = p11.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryLDto, MedicalHistory>> ProjectLDtoToMedicalHistory => p15 => new MedicalHistory()
        {
            ChiefComplaint = p15.ChiefComplaint,
            Section = p15.Section,
            FirstName = p15.FirstName,
            LastName = p15.LastName,
            FatherName = p15.FatherName,
            NationalId = p15.NationalId,
            Age = p15.Age,
            BirthDate = p15.BirthDate,
            PresentIllnessDetail = p15.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p15.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p15.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p15.FamilyHistoryDetail,
            AllergyDetail = p15.AllergyDetail,
            DrugHistoryDetail = p15.DrugHistoryDetail,
            AddictionHistoryDetail = p15.AddictionHistoryDetail,
            SystemReviewDetail = p15.SystemReviewDetail,
            VitalSignDetail = p15.VitalSignDetail,
            SystolicBloodPressure = p15.SystolicBloodPressure,
            DiastolicBloodPressure = p15.DiastolicBloodPressure,
            PulseRate = p15.PulseRate,
            SPO2 = p15.SPO2,
            Temperature = p15.Temperature,
            ApplicationUserId = p15.ApplicationUserId,
            Answers = p15.Answers.Select<MedicalHistoryAnswerSDto, MedicalHistoryAnswer>(p16 => new MedicalHistoryAnswer()
            {
                Answer = p16.Answer,
                Question = p16.Question,
                Part = p16.Part,
                QuestionType = p16.QuestionType,
                MedicalHistoryId = p16.MedicalHistoryId,
                Id = p16.Id
            }).ToList<MedicalHistoryAnswer>(),
            Id = p15.Id
        };
        public static MedicalHistoryLDto AdaptToLDto(this MedicalHistory p17)
        {
            return p17 == null ? null : new MedicalHistoryLDto()
            {
                ChiefComplaint = p17.ChiefComplaint,
                Section = p17.Section,
                FirstName = p17.FirstName,
                LastName = p17.LastName,
                FatherName = p17.FatherName,
                NationalId = p17.NationalId,
                Age = p17.Age,
                BirthDate = p17.BirthDate,
                PresentIllnessDetail = p17.PresentIllnessDetail,
                PastDiseasesHistoryDetail = p17.PastDiseasesHistoryDetail,
                PastSurgeryHistoryDetail = p17.PastSurgeryHistoryDetail,
                FamilyHistoryDetail = p17.FamilyHistoryDetail,
                AllergyDetail = p17.AllergyDetail,
                DrugHistoryDetail = p17.DrugHistoryDetail,
                AddictionHistoryDetail = p17.AddictionHistoryDetail,
                SystemReviewDetail = p17.SystemReviewDetail,
                VitalSignDetail = p17.VitalSignDetail,
                SystolicBloodPressure = p17.SystolicBloodPressure,
                DiastolicBloodPressure = p17.DiastolicBloodPressure,
                PulseRate = p17.PulseRate,
                SPO2 = p17.SPO2,
                Temperature = p17.Temperature,
                ApplicationUserId = p17.ApplicationUserId,
                Answers = funcMain3(p17.Answers),
                Id = p17.Id
            };
        }
        public static MedicalHistoryLDto AdaptTo(this MedicalHistory p19, MedicalHistoryLDto p20)
        {
            if (p19 == null)
            {
                return null;
            }
            MedicalHistoryLDto result = p20 ?? new MedicalHistoryLDto();
            
            result.ChiefComplaint = p19.ChiefComplaint;
            result.Section = p19.Section;
            result.FirstName = p19.FirstName;
            result.LastName = p19.LastName;
            result.FatherName = p19.FatherName;
            result.NationalId = p19.NationalId;
            result.Age = p19.Age;
            result.BirthDate = p19.BirthDate;
            result.PresentIllnessDetail = p19.PresentIllnessDetail;
            result.PastDiseasesHistoryDetail = p19.PastDiseasesHistoryDetail;
            result.PastSurgeryHistoryDetail = p19.PastSurgeryHistoryDetail;
            result.FamilyHistoryDetail = p19.FamilyHistoryDetail;
            result.AllergyDetail = p19.AllergyDetail;
            result.DrugHistoryDetail = p19.DrugHistoryDetail;
            result.AddictionHistoryDetail = p19.AddictionHistoryDetail;
            result.SystemReviewDetail = p19.SystemReviewDetail;
            result.VitalSignDetail = p19.VitalSignDetail;
            result.SystolicBloodPressure = p19.SystolicBloodPressure;
            result.DiastolicBloodPressure = p19.DiastolicBloodPressure;
            result.PulseRate = p19.PulseRate;
            result.SPO2 = p19.SPO2;
            result.Temperature = p19.Temperature;
            result.ApplicationUserId = p19.ApplicationUserId;
            result.Answers = funcMain4(p19.Answers, result.Answers);
            result.Id = p19.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistory, MedicalHistoryLDto>> ProjectToLDto => p23 => new MedicalHistoryLDto()
        {
            ChiefComplaint = p23.ChiefComplaint,
            Section = p23.Section,
            FirstName = p23.FirstName,
            LastName = p23.LastName,
            FatherName = p23.FatherName,
            NationalId = p23.NationalId,
            Age = p23.Age,
            BirthDate = p23.BirthDate,
            PresentIllnessDetail = p23.PresentIllnessDetail,
            PastDiseasesHistoryDetail = p23.PastDiseasesHistoryDetail,
            PastSurgeryHistoryDetail = p23.PastSurgeryHistoryDetail,
            FamilyHistoryDetail = p23.FamilyHistoryDetail,
            AllergyDetail = p23.AllergyDetail,
            DrugHistoryDetail = p23.DrugHistoryDetail,
            AddictionHistoryDetail = p23.AddictionHistoryDetail,
            SystemReviewDetail = p23.SystemReviewDetail,
            VitalSignDetail = p23.VitalSignDetail,
            SystolicBloodPressure = p23.SystolicBloodPressure,
            DiastolicBloodPressure = p23.DiastolicBloodPressure,
            PulseRate = p23.PulseRate,
            SPO2 = p23.SPO2,
            Temperature = p23.Temperature,
            ApplicationUserId = p23.ApplicationUserId,
            Answers = p23.Answers.Select<MedicalHistoryAnswer, MedicalHistoryAnswerSDto>(p24 => new MedicalHistoryAnswerSDto()
            {
                Answer = p24.Answer,
                Question = p24.Question,
                Part = p24.Part,
                QuestionType = p24.QuestionType,
                MedicalHistoryId = p24.MedicalHistoryId,
                Id = p24.Id
            }).ToList<MedicalHistoryAnswerSDto>(),
            Id = p23.Id
        };
        
        private static List<MedicalHistoryAnswer> funcMain1(List<MedicalHistoryAnswerSDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswer> result = new List<MedicalHistoryAnswer>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswerSDto item = p10[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> funcMain2(List<MedicalHistoryAnswerSDto> p13, List<MedicalHistoryAnswer> p14)
        {
            if (p13 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswer> result = new List<MedicalHistoryAnswer>(p13.Count);
            
            int i = 0;
            int len = p13.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswerSDto item = p13[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> funcMain3(List<MedicalHistoryAnswer> p18)
        {
            if (p18 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswerSDto> result = new List<MedicalHistoryAnswerSDto>(p18.Count);
            
            int i = 0;
            int len = p18.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswer item = p18[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> funcMain4(List<MedicalHistoryAnswer> p21, List<MedicalHistoryAnswerSDto> p22)
        {
            if (p21 == null)
            {
                return null;
            }
            List<MedicalHistoryAnswerSDto> result = new List<MedicalHistoryAnswerSDto>(p21.Count);
            
            int i = 0;
            int len = p21.Count;
            
            while (i < len)
            {
                MedicalHistoryAnswer item = p21[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;
            
        }
    }
}