using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Brizco.Domain.Dtos.LargeDtos;
using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complexes;

namespace Brizco.Domain.Mappers
{
    public static partial class SectionMapper
    {
        public static Section AdaptToSection(this SectionSDto p1)
        {
            return p1 == null ? null : new Section()
            {
                Name = p1.Name,
                Description = p1.Description,
                ComplexId = p1.ComplexId,
                Id = p1.Id
            };
        }
        public static Section AdaptTo(this SectionSDto p2, Section p3)
        {
            if (p2 == null)
            {
                return null;
            }
            Section result = p3 ?? new Section();
            
            result.Name = p2.Name;
            result.Description = p2.Description;
            result.ComplexId = p2.ComplexId;
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<SectionSDto, Section>> ProjectToSection => p4 => new Section()
        {
            Name = p4.Name,
            Description = p4.Description,
            ComplexId = p4.ComplexId,
            Id = p4.Id
        };
        public static SectionSDto AdaptToSDto(this Section p5)
        {
            return p5 == null ? null : new SectionSDto()
            {
                Name = p5.Name,
                Description = p5.Description,
                ComplexId = p5.ComplexId,
                Id = p5.Id
            };
        }
        public static SectionSDto AdaptTo(this Section p6, SectionSDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            SectionSDto result = p7 ?? new SectionSDto();
            
            result.Name = p6.Name;
            result.Description = p6.Description;
            result.ComplexId = p6.ComplexId;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<Section, SectionSDto>> ProjectToSDto => p8 => new SectionSDto()
        {
            Name = p8.Name,
            Description = p8.Description,
            ComplexId = p8.ComplexId,
            Id = p8.Id
        };
        public static Section AdaptToSection(this SectionLDto p9)
        {
            return p9 == null ? null : new Section()
            {
                Name = p9.Name,
                Description = p9.Description,
                ComplexId = p9.ComplexId,
                Positions = funcMain1(p9.Positions),
                Id = p9.Id
            };
        }
        public static Section AdaptTo(this SectionLDto p11, Section p12)
        {
            if (p11 == null)
            {
                return null;
            }
            Section result = p12 ?? new Section();
            
            result.Name = p11.Name;
            result.Description = p11.Description;
            result.ComplexId = p11.ComplexId;
            result.Positions = funcMain2(p11.Positions, result.Positions);
            result.Id = p11.Id;
            return result;
            
        }
        public static SectionLDto AdaptToLDto(this Section p15)
        {
            return p15 == null ? null : new SectionLDto()
            {
                Name = p15.Name,
                Description = p15.Description,
                ComplexId = p15.ComplexId,
                Positions = funcMain3(p15.Positions),
                Id = p15.Id
            };
        }
        public static SectionLDto AdaptTo(this Section p17, SectionLDto p18)
        {
            if (p17 == null)
            {
                return null;
            }
            SectionLDto result = p18 ?? new SectionLDto();
            
            result.Name = p17.Name;
            result.Description = p17.Description;
            result.ComplexId = p17.ComplexId;
            result.Positions = funcMain4(p17.Positions, result.Positions);
            result.Id = p17.Id;
            return result;
            
        }
        public static Expression<Func<Section, SectionLDto>> ProjectToLDto => p21 => new SectionLDto()
        {
            Name = p21.Name,
            Description = p21.Description,
            ComplexId = p21.ComplexId,
            Positions = p21.Positions.Select<Position, PositionSDto>(p22 => new PositionSDto()
            {
                Name = p22.Name,
                Description = p22.Description,
                ComplexId = p22.ComplexId,
                SectionId = p22.SectionId,
                Id = p22.Id
            }).ToList<PositionSDto>(),
            Id = p21.Id
        };
        
        private static List<Position> funcMain1(List<PositionSDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<Position> result = new List<Position>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                PositionSDto item = p10[i];
                result.Add(item == null ? null : new Position()
                {
                    Name = item.Name,
                    Description = item.Description,
                    ComplexId = item.ComplexId,
                    SectionId = item.SectionId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<Position> funcMain2(List<PositionSDto> p13, List<Position> p14)
        {
            if (p13 == null)
            {
                return null;
            }
            List<Position> result = new List<Position>(p13.Count);
            
            int i = 0;
            int len = p13.Count;
            
            while (i < len)
            {
                PositionSDto item = p13[i];
                result.Add(item == null ? null : new Position()
                {
                    Name = item.Name,
                    Description = item.Description,
                    ComplexId = item.ComplexId,
                    SectionId = item.SectionId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<PositionSDto> funcMain3(List<Position> p16)
        {
            if (p16 == null)
            {
                return null;
            }
            List<PositionSDto> result = new List<PositionSDto>(p16.Count);
            
            int i = 0;
            int len = p16.Count;
            
            while (i < len)
            {
                Position item = p16[i];
                result.Add(item == null ? null : new PositionSDto()
                {
                    Name = item.Name,
                    Description = item.Description,
                    ComplexId = item.ComplexId,
                    SectionId = item.SectionId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<PositionSDto> funcMain4(List<Position> p19, List<PositionSDto> p20)
        {
            if (p19 == null)
            {
                return null;
            }
            List<PositionSDto> result = new List<PositionSDto>(p19.Count);
            
            int i = 0;
            int len = p19.Count;
            
            while (i < len)
            {
                Position item = p19[i];
                result.Add(item == null ? null : new PositionSDto()
                {
                    Name = item.Name,
                    Description = item.Description,
                    ComplexId = item.ComplexId,
                    SectionId = item.SectionId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}