using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Brizco.Domain.Dtos.LargDtos;
using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Shift;

namespace Brizco.Domain.Mappers
{
    public static partial class ShiftPlanMapper
    {
        public static ShiftPlan AdaptToShiftPlan(this ShiftPlanSDto p1)
        {
            return p1 == null ? null : new ShiftPlan()
            {
                StartAt = p1.StartAt,
                EndAt = p1.EndAt,
                ShiftId = p1.ShiftId,
                Id = p1.Id
            };
        }
        public static ShiftPlan AdaptTo(this ShiftPlanSDto p2, ShiftPlan p3)
        {
            if (p2 == null)
            {
                return null;
            }
            ShiftPlan result = p3 ?? new ShiftPlan();
            
            result.StartAt = p2.StartAt;
            result.EndAt = p2.EndAt;
            result.ShiftId = p2.ShiftId;
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlanSDto, ShiftPlan>> ProjectToShiftPlan => p4 => new ShiftPlan()
        {
            StartAt = p4.StartAt,
            EndAt = p4.EndAt,
            ShiftId = p4.ShiftId,
            Id = p4.Id
        };
        public static ShiftPlanSDto AdaptToSDto(this ShiftPlan p5)
        {
            return p5 == null ? null : new ShiftPlanSDto()
            {
                StartAt = p5.StartAt,
                EndAt = p5.EndAt,
                ShiftId = p5.ShiftId,
                ShiftTitle = p5.Shift == null ? null : p5.Shift.Title,
                Id = p5.Id
            };
        }
        public static ShiftPlanSDto AdaptTo(this ShiftPlan p6, ShiftPlanSDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            ShiftPlanSDto result = p7 ?? new ShiftPlanSDto();
            
            result.StartAt = p6.StartAt;
            result.EndAt = p6.EndAt;
            result.ShiftId = p6.ShiftId;
            result.ShiftTitle = p6.Shift == null ? null : p6.Shift.Title;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlan, ShiftPlanSDto>> ProjectToSDto => p8 => new ShiftPlanSDto()
        {
            StartAt = p8.StartAt,
            EndAt = p8.EndAt,
            ShiftId = p8.ShiftId,
            ShiftTitle = p8.Shift.Title,
            Id = p8.Id
        };
        public static ShiftPlan AdaptToShiftPlan(this ShiftPlanLDto p9)
        {
            return p9 == null ? null : new ShiftPlan()
            {
                StartAt = p9.StartAt,
                EndAt = p9.EndAt,
                ShiftId = p9.ShiftId,
                Users = funcMain1(p9.Users),
                Id = p9.Id
            };
        }
        public static ShiftPlan AdaptTo(this ShiftPlanLDto p11, ShiftPlan p12)
        {
            if (p11 == null)
            {
                return null;
            }
            ShiftPlan result = p12 ?? new ShiftPlan();
            
            result.StartAt = p11.StartAt;
            result.EndAt = p11.EndAt;
            result.ShiftId = p11.ShiftId;
            result.Users = funcMain2(p11.Users, result.Users);
            result.Id = p11.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlanLDto, ShiftPlan>> ProjectLDtoToShiftPlan => p15 => new ShiftPlan()
        {
            StartAt = p15.StartAt,
            EndAt = p15.EndAt,
            ShiftId = p15.ShiftId,
            Users = p15.Users.Select<ShiftPlanUserSDto, ShiftPlanUser>(p16 => new ShiftPlanUser()
            {
                ShiftPlanId = p16.ShiftPlanId,
                ApplicationUserId = p16.ApplicationUserId,
                Id = p16.Id
            }).ToList<ShiftPlanUser>(),
            Id = p15.Id
        };
        public static ShiftPlanLDto AdaptToLDto(this ShiftPlan p17)
        {
            return p17 == null ? null : new ShiftPlanLDto()
            {
                StartAt = p17.StartAt,
                EndAt = p17.EndAt,
                ShiftId = p17.ShiftId,
                Users = funcMain3(p17.Users),
                Id = p17.Id
            };
        }
        public static ShiftPlanLDto AdaptTo(this ShiftPlan p19, ShiftPlanLDto p20)
        {
            if (p19 == null)
            {
                return null;
            }
            ShiftPlanLDto result = p20 ?? new ShiftPlanLDto();
            
            result.StartAt = p19.StartAt;
            result.EndAt = p19.EndAt;
            result.ShiftId = p19.ShiftId;
            result.Users = funcMain4(p19.Users, result.Users);
            result.Id = p19.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlan, ShiftPlanLDto>> ProjectToLDto => p23 => new ShiftPlanLDto()
        {
            StartAt = p23.StartAt,
            EndAt = p23.EndAt,
            ShiftId = p23.ShiftId,
            Users = p23.Users.Select<ShiftPlanUser, ShiftPlanUserSDto>(p24 => new ShiftPlanUserSDto()
            {
                ShiftPlanId = p24.ShiftPlanId,
                ApplicationUserId = p24.ApplicationUserId,
                Id = p24.Id
            }).ToList<ShiftPlanUserSDto>(),
            Id = p23.Id
        };
        
        private static List<ShiftPlanUser> funcMain1(List<ShiftPlanUserSDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<ShiftPlanUser> result = new List<ShiftPlanUser>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                ShiftPlanUserSDto item = p10[i];
                result.Add(item == null ? null : new ShiftPlanUser()
                {
                    ShiftPlanId = item.ShiftPlanId,
                    ApplicationUserId = item.ApplicationUserId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<ShiftPlanUser> funcMain2(List<ShiftPlanUserSDto> p13, List<ShiftPlanUser> p14)
        {
            if (p13 == null)
            {
                return null;
            }
            List<ShiftPlanUser> result = new List<ShiftPlanUser>(p13.Count);
            
            int i = 0;
            int len = p13.Count;
            
            while (i < len)
            {
                ShiftPlanUserSDto item = p13[i];
                result.Add(item == null ? null : new ShiftPlanUser()
                {
                    ShiftPlanId = item.ShiftPlanId,
                    ApplicationUserId = item.ApplicationUserId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<ShiftPlanUserSDto> funcMain3(List<ShiftPlanUser> p18)
        {
            if (p18 == null)
            {
                return null;
            }
            List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p18.Count);
            
            int i = 0;
            int len = p18.Count;
            
            while (i < len)
            {
                ShiftPlanUser item = p18[i];
                result.Add(item == null ? null : new ShiftPlanUserSDto()
                {
                    ShiftPlanId = item.ShiftPlanId,
                    ApplicationUserId = item.ApplicationUserId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<ShiftPlanUserSDto> funcMain4(List<ShiftPlanUser> p21, List<ShiftPlanUserSDto> p22)
        {
            if (p21 == null)
            {
                return null;
            }
            List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p21.Count);
            
            int i = 0;
            int len = p21.Count;
            
            while (i < len)
            {
                ShiftPlanUser item = p21[i];
                result.Add(item == null ? null : new ShiftPlanUserSDto()
                {
                    ShiftPlanId = item.ShiftPlanId,
                    ApplicationUserId = item.ApplicationUserId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}