using System;
using System.Linq.Expressions;
using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complex;
using Brizco.Domain.Entities.Shift;
using Brizco.Domain.Entities.User;
using Mapster.Models;

namespace Brizco.Domain.Mappers
{
    public static partial class ShiftPlanUserMapper
    {
        public static ShiftPlanUser AdaptToShiftPlanUser(this ShiftPlanUserSDto p1)
        {
            return p1 == null ? null : new ShiftPlanUser()
            {
                ShiftPlanId = p1.ShiftPlanId,
                ShiftPlan = new ShiftPlan() {Id = p1.ShiftPlanId},
                PositionId = p1.PositionId,
                Position = new Position()
                {
                    Name = p1.PositionName,
                    Id = p1.PositionId
                },
                UserId = p1.UserId,
                User = new ApplicationUser() {Id = p1.UserId},
                Id = p1.Id
            };
        }
        public static ShiftPlanUser AdaptTo(this ShiftPlanUserSDto p2, ShiftPlanUser p3)
        {
            if (p2 == null)
            {
                return null;
            }
            ShiftPlanUser result = p3 ?? new ShiftPlanUser();
            
            result.ShiftPlanId = p2.ShiftPlanId;
            result.ShiftPlan = funcMain1(new Never(), result.ShiftPlan, p2);
            result.PositionId = p2.PositionId;
            result.Position = funcMain2(new Never(), result.Position, p2);
            result.UserId = p2.UserId;
            result.User = funcMain3(new Never(), result.User, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlanUserSDto, ShiftPlanUser>> ProjectToShiftPlanUser => p10 => new ShiftPlanUser()
        {
            ShiftPlanId = p10.ShiftPlanId,
            ShiftPlan = new ShiftPlan() {Id = p10.ShiftPlanId},
            PositionId = p10.PositionId,
            Position = new Position()
            {
                Name = p10.PositionName,
                Id = p10.PositionId
            },
            UserId = p10.UserId,
            User = new ApplicationUser() {Id = p10.UserId},
            Id = p10.Id
        };
        public static ShiftPlanUserSDto AdaptToSDto(this ShiftPlanUser p11)
        {
            return p11 == null ? null : new ShiftPlanUserSDto()
            {
                ShiftPlanId = p11.ShiftPlanId,
                UserId = p11.UserId,
                UserFullName = p11.User != null ? p11.User.FirstName + " " + p11.User.LastName : string.Empty,
                PositionId = p11.PositionId,
                PositionName = p11.Position != null ? p11.Position.Name : string.Empty,
                Id = p11.Id
            };
        }
        public static ShiftPlanUserSDto AdaptTo(this ShiftPlanUser p12, ShiftPlanUserSDto p13)
        {
            if (p12 == null)
            {
                return null;
            }
            ShiftPlanUserSDto result = p13 ?? new ShiftPlanUserSDto();
            
            result.ShiftPlanId = p12.ShiftPlanId;
            result.UserId = p12.UserId;
            result.UserFullName = p12.User != null ? p12.User.FirstName + " " + p12.User.LastName : string.Empty;
            result.PositionId = p12.PositionId;
            result.PositionName = p12.Position != null ? p12.Position.Name : string.Empty;
            result.Id = p12.Id;
            return result;
            
        }
        public static Expression<Func<ShiftPlanUser, ShiftPlanUserSDto>> ProjectToSDto => p14 => new ShiftPlanUserSDto()
        {
            ShiftPlanId = p14.ShiftPlanId,
            UserId = p14.UserId,
            UserFullName = p14.User != null ? p14.User.FirstName + " " + p14.User.LastName : string.Empty,
            PositionId = p14.PositionId,
            PositionName = p14.Position != null ? p14.Position.Name : string.Empty,
            Id = p14.Id
        };
        
        private static ShiftPlan funcMain1(Never p4, ShiftPlan p5, ShiftPlanUserSDto p2)
        {
            ShiftPlan result = p5 ?? new ShiftPlan();
            
            result.Id = p2.ShiftPlanId;
            return result;
            
        }
        
        private static Position funcMain2(Never p6, Position p7, ShiftPlanUserSDto p2)
        {
            Position result = p7 ?? new Position();
            
            result.Name = p2.PositionName;
            result.Id = p2.PositionId;
            return result;
            
        }
        
        private static ApplicationUser funcMain3(Never p8, ApplicationUser p9, ShiftPlanUserSDto p2)
        {
            ApplicationUser result = p9 ?? new ApplicationUser();
            
            result.Id = p2.UserId;
            return result;
            
        }
    }
}