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;

namespace DocuMed.Domain.Mappers
{
    public static partial class CityMapper
    {
        public static City AdaptToCity(this CitySDto p1)
        {
            return p1 == null ? null : new City()
            {
                Name = p1.Name,
                Id = p1.Id
            };
        }
        public static City AdaptTo(this CitySDto p2, City p3)
        {
            if (p2 == null)
            {
                return null;
            }
            City result = p3 ?? new City();
            
            result.Name = p2.Name;
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<CitySDto, City>> ProjectToCity => p4 => new City()
        {
            Name = p4.Name,
            Id = p4.Id
        };
        public static CitySDto AdaptToSDto(this City p5)
        {
            return p5 == null ? null : new CitySDto()
            {
                Name = p5.Name,
                Id = p5.Id
            };
        }
        public static CitySDto AdaptTo(this City p6, CitySDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            CitySDto result = p7 ?? new CitySDto();
            
            result.Name = p6.Name;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<City, CitySDto>> ProjectToSDto => p8 => new CitySDto()
        {
            Name = p8.Name,
            Id = p8.Id
        };
        public static City AdaptToCity(this CityLDto p9)
        {
            return p9 == null ? null : new City()
            {
                Name = p9.Name,
                Universities = funcMain1(p9.Universities),
                Id = p9.Id
            };
        }
        public static City AdaptTo(this CityLDto p11, City p12)
        {
            if (p11 == null)
            {
                return null;
            }
            City result = p12 ?? new City();
            
            result.Name = p11.Name;
            result.Universities = funcMain2(p11.Universities, result.Universities);
            result.Id = p11.Id;
            return result;
            
        }
        public static Expression<Func<CityLDto, City>> ProjectLDtoToCity => p15 => new City()
        {
            Name = p15.Name,
            Universities = p15.Universities.Select<UniversitySDto, University>(p16 => new University()
            {
                Name = p16.Name,
                Address = p16.Address,
                CityId = p16.CityId,
                Id = p16.Id
            }).ToList<University>(),
            Id = p15.Id
        };
        public static CityLDto AdaptToLDto(this City p17)
        {
            return p17 == null ? null : new CityLDto()
            {
                Name = p17.Name,
                Universities = funcMain3(p17.Universities),
                Id = p17.Id
            };
        }
        public static CityLDto AdaptTo(this City p19, CityLDto p20)
        {
            if (p19 == null)
            {
                return null;
            }
            CityLDto result = p20 ?? new CityLDto();
            
            result.Name = p19.Name;
            result.Universities = funcMain4(p19.Universities, result.Universities);
            result.Id = p19.Id;
            return result;
            
        }
        public static Expression<Func<City, CityLDto>> ProjectToLDto => p23 => new CityLDto()
        {
            Name = p23.Name,
            Universities = p23.Universities.Select<University, UniversitySDto>(p24 => new UniversitySDto()
            {
                Name = p24.Name,
                Address = p24.Address,
                CityId = p24.CityId,
                Id = p24.Id
            }).ToList<UniversitySDto>(),
            Id = p23.Id
        };
        
        private static List<University> funcMain1(List<UniversitySDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<University> result = new List<University>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                UniversitySDto item = p10[i];
                result.Add(item == null ? null : new University()
                {
                    Name = item.Name,
                    Address = item.Address,
                    CityId = item.CityId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<University> funcMain2(List<UniversitySDto> p13, List<University> p14)
        {
            if (p13 == null)
            {
                return null;
            }
            List<University> result = new List<University>(p13.Count);
            
            int i = 0;
            int len = p13.Count;
            
            while (i < len)
            {
                UniversitySDto item = p13[i];
                result.Add(item == null ? null : new University()
                {
                    Name = item.Name,
                    Address = item.Address,
                    CityId = item.CityId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<UniversitySDto> funcMain3(List<University> p18)
        {
            if (p18 == null)
            {
                return null;
            }
            List<UniversitySDto> result = new List<UniversitySDto>(p18.Count);
            
            int i = 0;
            int len = p18.Count;
            
            while (i < len)
            {
                University item = p18[i];
                result.Add(item == null ? null : new UniversitySDto()
                {
                    Name = item.Name,
                    Address = item.Address,
                    CityId = item.CityId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<UniversitySDto> funcMain4(List<University> p21, List<UniversitySDto> p22)
        {
            if (p21 == null)
            {
                return null;
            }
            List<UniversitySDto> result = new List<UniversitySDto>(p21.Count);
            
            int i = 0;
            int len = p21.Count;
            
            while (i < len)
            {
                University item = p21[i];
                result.Add(item == null ? null : new UniversitySDto()
                {
                    Name = item.Name,
                    Address = item.Address,
                    CityId = item.CityId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}