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.Task;
using Task = Brizco.Domain.Entities.Task.Task;

namespace Brizco.Domain.Mappers
{
    public static partial class TaskMapper
    {
        public static Task AdaptToTask(this TaskSDto p1)
        {
            return p1 == null ? null : new Task()
            {
                Type = p1.Type,
                Title = p1.Title,
                Description = p1.Description,
                IsRelatedToRole = p1.IsRelatedToRole,
                IsRelatedToPerson = p1.IsRelatedToPerson,
                IsDisposable = p1.IsDisposable,
                SetFor = p1.SetFor,
                HasDisposed = p1.HasDisposed,
                ComplexId = p1.ComplexId,
                Amount = p1.Amount,
                AmountType = p1.AmountType,
                Id = p1.Id
            };
        }
        public static Task AdaptTo(this TaskSDto p2, Task p3)
        {
            if (p2 == null)
            {
                return null;
            }
            Task result = p3 ?? new Task();
            
            result.Type = p2.Type;
            result.Title = p2.Title;
            result.Description = p2.Description;
            result.IsRelatedToRole = p2.IsRelatedToRole;
            result.IsRelatedToPerson = p2.IsRelatedToPerson;
            result.IsDisposable = p2.IsDisposable;
            result.SetFor = p2.SetFor;
            result.HasDisposed = p2.HasDisposed;
            result.ComplexId = p2.ComplexId;
            result.Amount = p2.Amount;
            result.AmountType = p2.AmountType;
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<TaskSDto, Task>> ProjectToTask => p4 => new Task()
        {
            Type = p4.Type,
            Title = p4.Title,
            Description = p4.Description,
            IsRelatedToRole = p4.IsRelatedToRole,
            IsRelatedToPerson = p4.IsRelatedToPerson,
            IsDisposable = p4.IsDisposable,
            SetFor = p4.SetFor,
            HasDisposed = p4.HasDisposed,
            ComplexId = p4.ComplexId,
            Amount = p4.Amount,
            AmountType = p4.AmountType,
            Id = p4.Id
        };
        public static TaskSDto AdaptToSDto(this Task p5)
        {
            return p5 == null ? null : new TaskSDto()
            {
                Type = p5.Type,
                Title = p5.Title,
                Description = p5.Description,
                IsRelatedToRole = p5.IsRelatedToRole,
                IsRelatedToPerson = p5.IsRelatedToPerson,
                IsDisposable = p5.IsDisposable,
                SetFor = p5.SetFor,
                HasDisposed = p5.HasDisposed,
                ComplexId = p5.ComplexId,
                Amount = p5.Amount,
                AmountType = p5.AmountType,
                Id = p5.Id
            };
        }
        public static TaskSDto AdaptTo(this Task p6, TaskSDto p7)
        {
            if (p6 == null)
            {
                return null;
            }
            TaskSDto result = p7 ?? new TaskSDto();
            
            result.Type = p6.Type;
            result.Title = p6.Title;
            result.Description = p6.Description;
            result.IsRelatedToRole = p6.IsRelatedToRole;
            result.IsRelatedToPerson = p6.IsRelatedToPerson;
            result.IsDisposable = p6.IsDisposable;
            result.SetFor = p6.SetFor;
            result.HasDisposed = p6.HasDisposed;
            result.ComplexId = p6.ComplexId;
            result.Amount = p6.Amount;
            result.AmountType = p6.AmountType;
            result.Id = p6.Id;
            return result;
            
        }
        public static Expression<Func<Task, TaskSDto>> ProjectToSDto => p8 => new TaskSDto()
        {
            Type = p8.Type,
            Title = p8.Title,
            Description = p8.Description,
            IsRelatedToRole = p8.IsRelatedToRole,
            IsRelatedToPerson = p8.IsRelatedToPerson,
            IsDisposable = p8.IsDisposable,
            SetFor = p8.SetFor,
            HasDisposed = p8.HasDisposed,
            ComplexId = p8.ComplexId,
            Amount = p8.Amount,
            AmountType = p8.AmountType,
            Id = p8.Id
        };
        public static Task AdaptToTask(this TaskLDto p9)
        {
            return p9 == null ? null : new Task()
            {
                Type = p9.Type,
                Title = p9.Title,
                Description = p9.Description,
                IsRelatedToRole = p9.IsRelatedToRole,
                IsRelatedToPerson = p9.IsRelatedToPerson,
                IsDisposable = p9.IsDisposable,
                SetFor = p9.SetFor,
                HasDisposed = p9.HasDisposed,
                Amount = p9.Amount,
                AmountType = p9.AmountType,
                Users = funcMain1(p9.Users),
                Shifts = funcMain2(p9.Shifts),
                Roles = funcMain3(p9.Roles),
                Id = p9.Id
            };
        }
        public static Task AdaptTo(this TaskLDto p13, Task p14)
        {
            if (p13 == null)
            {
                return null;
            }
            Task result = p14 ?? new Task();
            
            result.Type = p13.Type;
            result.Title = p13.Title;
            result.Description = p13.Description;
            result.IsRelatedToRole = p13.IsRelatedToRole;
            result.IsRelatedToPerson = p13.IsRelatedToPerson;
            result.IsDisposable = p13.IsDisposable;
            result.SetFor = p13.SetFor;
            result.HasDisposed = p13.HasDisposed;
            result.Amount = p13.Amount;
            result.AmountType = p13.AmountType;
            result.Users = funcMain4(p13.Users, result.Users);
            result.Shifts = funcMain5(p13.Shifts, result.Shifts);
            result.Roles = funcMain6(p13.Roles, result.Roles);
            result.Id = p13.Id;
            return result;
            
        }
        public static Expression<Func<TaskLDto, Task>> ProjectLDtoToTask => p21 => new Task()
        {
            Type = p21.Type,
            Title = p21.Title,
            Description = p21.Description,
            IsRelatedToRole = p21.IsRelatedToRole,
            IsRelatedToPerson = p21.IsRelatedToPerson,
            IsDisposable = p21.IsDisposable,
            SetFor = p21.SetFor,
            HasDisposed = p21.HasDisposed,
            Amount = p21.Amount,
            AmountType = p21.AmountType,
            Users = p21.Users.Select<TaskUserSDto, TaskUser>(p22 => new TaskUser()
            {
                UserId = p22.UserId,
                TaskId = p22.TaskId
            }).ToList<TaskUser>(),
            Shifts = p21.Shifts.Select<TaskShiftSDto, TaskShift>(p23 => new TaskShift()
            {
                TaskId = p23.TaskId,
                ShiftId = p23.ShiftId
            }).ToList<TaskShift>(),
            Roles = p21.Roles.Select<TaskRoleSDto, TaskRole>(p24 => new TaskRole()
            {
                RoleId = p24.RoleId,
                TaskId = p24.TaskId,
                Id = p24.Id
            }).ToList<TaskRole>(),
            Id = p21.Id
        };
        public static TaskLDto AdaptToLDto(this Task p25)
        {
            return p25 == null ? null : new TaskLDto()
            {
                Type = p25.Type,
                Title = p25.Title,
                Description = p25.Description,
                IsRelatedToRole = p25.IsRelatedToRole,
                IsRelatedToPerson = p25.IsRelatedToPerson,
                IsDisposable = p25.IsDisposable,
                SetFor = p25.SetFor,
                HasDisposed = p25.HasDisposed,
                Amount = p25.Amount,
                AmountType = p25.AmountType,
                Users = funcMain7(p25.Users),
                Shifts = funcMain8(p25.Shifts),
                Roles = funcMain9(p25.Roles),
                Id = p25.Id
            };
        }
        public static TaskLDto AdaptTo(this Task p29, TaskLDto p30)
        {
            if (p29 == null)
            {
                return null;
            }
            TaskLDto result = p30 ?? new TaskLDto();
            
            result.Type = p29.Type;
            result.Title = p29.Title;
            result.Description = p29.Description;
            result.IsRelatedToRole = p29.IsRelatedToRole;
            result.IsRelatedToPerson = p29.IsRelatedToPerson;
            result.IsDisposable = p29.IsDisposable;
            result.SetFor = p29.SetFor;
            result.HasDisposed = p29.HasDisposed;
            result.Amount = p29.Amount;
            result.AmountType = p29.AmountType;
            result.Users = funcMain10(p29.Users, result.Users);
            result.Shifts = funcMain11(p29.Shifts, result.Shifts);
            result.Roles = funcMain12(p29.Roles, result.Roles);
            result.Id = p29.Id;
            return result;
            
        }
        public static Expression<Func<Task, TaskLDto>> ProjectToLDto => p37 => new TaskLDto()
        {
            Type = p37.Type,
            Title = p37.Title,
            Description = p37.Description,
            IsRelatedToRole = p37.IsRelatedToRole,
            IsRelatedToPerson = p37.IsRelatedToPerson,
            IsDisposable = p37.IsDisposable,
            SetFor = p37.SetFor,
            HasDisposed = p37.HasDisposed,
            Amount = p37.Amount,
            AmountType = p37.AmountType,
            Users = p37.Users.Select<TaskUser, TaskUserSDto>(p38 => new TaskUserSDto()
            {
                UserId = p38.UserId,
                TaskId = p38.TaskId
            }).ToList<TaskUserSDto>(),
            Shifts = p37.Shifts.Select<TaskShift, TaskShiftSDto>(p39 => new TaskShiftSDto()
            {
                ShiftId = p39.ShiftId,
                TaskId = p39.TaskId
            }).ToList<TaskShiftSDto>(),
            Roles = p37.Roles.Select<TaskRole, TaskRoleSDto>(p40 => new TaskRoleSDto()
            {
                RoleId = p40.RoleId,
                TaskId = p40.TaskId,
                Id = p40.Id
            }).ToList<TaskRoleSDto>(),
            Id = p37.Id
        };
        
        private static List<TaskUser> funcMain1(List<TaskUserSDto> p10)
        {
            if (p10 == null)
            {
                return null;
            }
            List<TaskUser> result = new List<TaskUser>(p10.Count);
            
            int i = 0;
            int len = p10.Count;
            
            while (i < len)
            {
                TaskUserSDto item = p10[i];
                result.Add(item == null ? null : new TaskUser()
                {
                    UserId = item.UserId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskShift> funcMain2(List<TaskShiftSDto> p11)
        {
            if (p11 == null)
            {
                return null;
            }
            List<TaskShift> result = new List<TaskShift>(p11.Count);
            
            int i = 0;
            int len = p11.Count;
            
            while (i < len)
            {
                TaskShiftSDto item = p11[i];
                result.Add(item == null ? null : new TaskShift()
                {
                    TaskId = item.TaskId,
                    ShiftId = item.ShiftId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskRole> funcMain3(List<TaskRoleSDto> p12)
        {
            if (p12 == null)
            {
                return null;
            }
            List<TaskRole> result = new List<TaskRole>(p12.Count);
            
            int i = 0;
            int len = p12.Count;
            
            while (i < len)
            {
                TaskRoleSDto item = p12[i];
                result.Add(item == null ? null : new TaskRole()
                {
                    RoleId = item.RoleId,
                    TaskId = item.TaskId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskUser> funcMain4(List<TaskUserSDto> p15, List<TaskUser> p16)
        {
            if (p15 == null)
            {
                return null;
            }
            List<TaskUser> result = new List<TaskUser>(p15.Count);
            
            int i = 0;
            int len = p15.Count;
            
            while (i < len)
            {
                TaskUserSDto item = p15[i];
                result.Add(item == null ? null : new TaskUser()
                {
                    UserId = item.UserId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskShift> funcMain5(List<TaskShiftSDto> p17, List<TaskShift> p18)
        {
            if (p17 == null)
            {
                return null;
            }
            List<TaskShift> result = new List<TaskShift>(p17.Count);
            
            int i = 0;
            int len = p17.Count;
            
            while (i < len)
            {
                TaskShiftSDto item = p17[i];
                result.Add(item == null ? null : new TaskShift()
                {
                    TaskId = item.TaskId,
                    ShiftId = item.ShiftId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskRole> funcMain6(List<TaskRoleSDto> p19, List<TaskRole> p20)
        {
            if (p19 == null)
            {
                return null;
            }
            List<TaskRole> result = new List<TaskRole>(p19.Count);
            
            int i = 0;
            int len = p19.Count;
            
            while (i < len)
            {
                TaskRoleSDto item = p19[i];
                result.Add(item == null ? null : new TaskRole()
                {
                    RoleId = item.RoleId,
                    TaskId = item.TaskId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskUserSDto> funcMain7(List<TaskUser> p26)
        {
            if (p26 == null)
            {
                return null;
            }
            List<TaskUserSDto> result = new List<TaskUserSDto>(p26.Count);
            
            int i = 0;
            int len = p26.Count;
            
            while (i < len)
            {
                TaskUser item = p26[i];
                result.Add(item == null ? null : new TaskUserSDto()
                {
                    UserId = item.UserId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskShiftSDto> funcMain8(List<TaskShift> p27)
        {
            if (p27 == null)
            {
                return null;
            }
            List<TaskShiftSDto> result = new List<TaskShiftSDto>(p27.Count);
            
            int i = 0;
            int len = p27.Count;
            
            while (i < len)
            {
                TaskShift item = p27[i];
                result.Add(item == null ? null : new TaskShiftSDto()
                {
                    ShiftId = item.ShiftId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskRoleSDto> funcMain9(List<TaskRole> p28)
        {
            if (p28 == null)
            {
                return null;
            }
            List<TaskRoleSDto> result = new List<TaskRoleSDto>(p28.Count);
            
            int i = 0;
            int len = p28.Count;
            
            while (i < len)
            {
                TaskRole item = p28[i];
                result.Add(item == null ? null : new TaskRoleSDto()
                {
                    RoleId = item.RoleId,
                    TaskId = item.TaskId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskUserSDto> funcMain10(List<TaskUser> p31, List<TaskUserSDto> p32)
        {
            if (p31 == null)
            {
                return null;
            }
            List<TaskUserSDto> result = new List<TaskUserSDto>(p31.Count);
            
            int i = 0;
            int len = p31.Count;
            
            while (i < len)
            {
                TaskUser item = p31[i];
                result.Add(item == null ? null : new TaskUserSDto()
                {
                    UserId = item.UserId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskShiftSDto> funcMain11(List<TaskShift> p33, List<TaskShiftSDto> p34)
        {
            if (p33 == null)
            {
                return null;
            }
            List<TaskShiftSDto> result = new List<TaskShiftSDto>(p33.Count);
            
            int i = 0;
            int len = p33.Count;
            
            while (i < len)
            {
                TaskShift item = p33[i];
                result.Add(item == null ? null : new TaskShiftSDto()
                {
                    ShiftId = item.ShiftId,
                    TaskId = item.TaskId
                });
                i++;
            }
            return result;
            
        }
        
        private static List<TaskRoleSDto> funcMain12(List<TaskRole> p35, List<TaskRoleSDto> p36)
        {
            if (p35 == null)
            {
                return null;
            }
            List<TaskRoleSDto> result = new List<TaskRoleSDto>(p35.Count);
            
            int i = 0;
            int len = p35.Count;
            
            while (i < len)
            {
                TaskRole item = p35[i];
                result.Add(item == null ? null : new TaskRoleSDto()
                {
                    RoleId = item.RoleId,
                    TaskId = item.TaskId,
                    Id = item.Id
                });
                i++;
            }
            return result;
            
        }
    }
}