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

namespace DocuMed.Domain.Mappers
{
    public static partial class MedicalHistoryTemplateMapper
    {
        public static MedicalHistoryTemplate AdaptToMedicalHistoryTemplate(this MedicalHistoryTemplateSDto p1)
        {
            return p1 == null ? null : new MedicalHistoryTemplate()
            {
                ChiefComplaint = p1.ChiefComplaint,
                Id = p1.Id
            };
        }
        public static MedicalHistoryTemplate AdaptTo(this MedicalHistoryTemplateSDto p2, MedicalHistoryTemplate p3)
        {
            if (p2 == null)
            {
                return null;
            }
            MedicalHistoryTemplate result = p3 ?? new MedicalHistoryTemplate();
            
            result.ChiefComplaint = p2.ChiefComplaint;
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryTemplateSDto, MedicalHistoryTemplate>> ProjectToMedicalHistoryTemplate => p4 => new MedicalHistoryTemplate()
        {
            ChiefComplaint = p4.ChiefComplaint,
            Id = p4.Id
        };
        public static MedicalHistoryTemplateSDto AdaptToSDto(this MedicalHistoryTemplate p5)
        {
            return p5 == null ? null : new MedicalHistoryTemplateSDto()
            {
                ChiefComplaint = p5.ChiefComplaint,
                Id = p5.Id
            };
        }
        public static MedicalHistoryTemplateSDto AdaptTo(this MedicalHistoryTemplate p6, MedicalHistoryTemplateSDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            MedicalHistoryTemplateSDto result = p7 ?? new MedicalHistoryTemplateSDto();
            
            result.ChiefComplaint = p6.ChiefComplaint;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryTemplate, MedicalHistoryTemplateSDto>> ProjectToSDto => p8 => new MedicalHistoryTemplateSDto()
        {
            ChiefComplaint = p8.ChiefComplaint,
            Id = p8.Id
        };
        public static MedicalHistoryTemplate AdaptToMedicalHistoryTemplate(this MedicalHistoryTemplateLDto p9)
        {
            return p9 == null ? null : new MedicalHistoryTemplate()
            {
                ChiefComplaint = p9.ChiefComplaint,
                Questions = funcMain1(p9.Questions),
                Id = p9.Id
            };
        }
        public static MedicalHistoryTemplate AdaptTo(this MedicalHistoryTemplateLDto p11, MedicalHistoryTemplate p12)
        {
            if (p11 == null)
            {
                return null;
            }
            MedicalHistoryTemplate result = p12 ?? new MedicalHistoryTemplate();
            
            result.ChiefComplaint = p11.ChiefComplaint;
            result.Questions = funcMain2(p11.Questions, result.Questions);
            result.Id = p11.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryTemplateLDto, MedicalHistoryTemplate>> ProjectLDtoToMedicalHistoryTemplate => p15 => new MedicalHistoryTemplate()
        {
            ChiefComplaint = p15.ChiefComplaint,
            Questions = p15.Questions.Select<MedicalHistoryQuestionSDto, MedicalHistoryQuestion>(p16 => new MedicalHistoryQuestion()
            {
                Question = p16.Question,
                Part = p16.Part,
                QuestionType = p16.QuestionType,
                MedicalHistoryTemplateId = p16.MedicalHistoryTemplateId,
                Id = p16.Id
            }).ToList<MedicalHistoryQuestion>(),
            Id = p15.Id
        };
        public static MedicalHistoryTemplateLDto AdaptToLDto(this MedicalHistoryTemplate p17)
        {
            return p17 == null ? null : new MedicalHistoryTemplateLDto()
            {
                ChiefComplaint = p17.ChiefComplaint,
                Questions = funcMain3(p17.Questions),
                Id = p17.Id
            };
        }
        public static MedicalHistoryTemplateLDto AdaptTo(this MedicalHistoryTemplate p19, MedicalHistoryTemplateLDto p20)
        {
            if (p19 == null)
            {
                return null;
            }
            MedicalHistoryTemplateLDto result = p20 ?? new MedicalHistoryTemplateLDto();
            
            result.ChiefComplaint = p19.ChiefComplaint;
            result.Questions = funcMain4(p19.Questions, result.Questions);
            result.Id = p19.Id;
            return result;
            
        }
        public static Expression<Func<MedicalHistoryTemplate, MedicalHistoryTemplateLDto>> ProjectToLDto => p23 => new MedicalHistoryTemplateLDto()
        {
            ChiefComplaint = p23.ChiefComplaint,
            Questions = p23.Questions.Select<MedicalHistoryQuestion, MedicalHistoryQuestionSDto>(p24 => new MedicalHistoryQuestionSDto()
            {
                Question = p24.Question,
                Part = p24.Part,
                QuestionType = p24.QuestionType,
                MedicalHistoryTemplateId = p24.MedicalHistoryTemplateId,
                Id = p24.Id
            }).ToList<MedicalHistoryQuestionSDto>(),
            Id = p23.Id
        };
        
        private static List<MedicalHistoryQuestion> funcMain1(List<MedicalHistoryQuestionSDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<MedicalHistoryQuestion> result = new List<MedicalHistoryQuestion>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                MedicalHistoryQuestionSDto item = p10[i];
                result.Add(item == null ? null : new MedicalHistoryQuestion()
                {
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryTemplateId = item.MedicalHistoryTemplateId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryQuestion> funcMain2(List<MedicalHistoryQuestionSDto> p13, List<MedicalHistoryQuestion> p14)
        {
            if (p13 == null)
            {
                return null;
            }
            List<MedicalHistoryQuestion> result = new List<MedicalHistoryQuestion>(p13.Count);
            
            int i = 0;
            int len = p13.Count;
            
            while (i < len)
            {
                MedicalHistoryQuestionSDto item = p13[i];
                result.Add(item == null ? null : new MedicalHistoryQuestion()
                {
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryTemplateId = item.MedicalHistoryTemplateId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryQuestionSDto> funcMain3(List<MedicalHistoryQuestion> p18)
        {
            if (p18 == null)
            {
                return null;
            }
            List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p18.Count);
            
            int i = 0;
            int len = p18.Count;
            
            while (i < len)
            {
                MedicalHistoryQuestion item = p18[i];
                result.Add(item == null ? null : new MedicalHistoryQuestionSDto()
                {
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryTemplateId = item.MedicalHistoryTemplateId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<MedicalHistoryQuestionSDto> funcMain4(List<MedicalHistoryQuestion> p21, List<MedicalHistoryQuestionSDto> p22)
        {
            if (p21 == null)
            {
                return null;
            }
            List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p21.Count);
            
            int i = 0;
            int len = p21.Count;
            
            while (i < len)
            {
                MedicalHistoryQuestion item = p21[i];
                result.Add(item == null ? null : new MedicalHistoryQuestionSDto()
                {
                    Question = item.Question,
                    Part = item.Part,
                    QuestionType = item.QuestionType,
                    MedicalHistoryTemplateId = item.MedicalHistoryTemplateId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}