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