using System;
using System.Linq.Expressions;
using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complex;
using Brizco.Domain.Entities.Task;
using Mapster.Models;
using Task = Brizco.Domain.Entities.Task.Task;

namespace Brizco.Domain.Mappers
{
    public static partial class TaskPositionMapper
    {
        public static TaskPosition AdaptToTaskPosition(this TaskPositionSDto p1)
        {
            return p1 == null ? null : new TaskPosition()
            {
                PositionId = p1.PositionId,
                Position = new Position()
                {
                    Name = p1.PositionName,
                    Id = p1.PositionId
                },
                TaskId = p1.TaskId,
                Task = new Task() {Id = p1.TaskId},
                Id = p1.Id
            };
        }
        public static TaskPosition AdaptTo(this TaskPositionSDto p2, TaskPosition p3)
        {
            if (p2 == null)
            {
                return null;
            }
            TaskPosition result = p3 ?? new TaskPosition();
            
            result.PositionId = p2.PositionId;
            result.Position = funcMain1(new Never(), result.Position, p2);
            result.TaskId = p2.TaskId;
            result.Task = funcMain2(new Never(), result.Task, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<TaskPositionSDto, TaskPosition>> ProjectToTaskPosition => p8 => new TaskPosition()
        {
            PositionId = p8.PositionId,
            Position = new Position()
            {
                Name = p8.PositionName,
                Id = p8.PositionId
            },
            TaskId = p8.TaskId,
            Task = new Task() {Id = p8.TaskId},
            Id = p8.Id
        };
        public static TaskPositionSDto AdaptToSDto(this TaskPosition p9)
        {
            return p9 == null ? null : new TaskPositionSDto()
            {
                PositionId = p9.PositionId,
                PositionName = p9.Position != null ? p9.Position.Name : string.Empty,
                TaskId = p9.TaskId,
                Id = p9.Id
            };
        }
        public static TaskPositionSDto AdaptTo(this TaskPosition p10, TaskPositionSDto p11)
        {
            if (p10 == null)
            {
                return null;
            }
            TaskPositionSDto result = p11 ?? new TaskPositionSDto();
            
            result.PositionId = p10.PositionId;
            result.PositionName = p10.Position != null ? p10.Position.Name : string.Empty;
            result.TaskId = p10.TaskId;
            result.Id = p10.Id;
            return result;
            
        }
        public static Expression<Func<TaskPosition, TaskPositionSDto>> ProjectToSDto => p12 => new TaskPositionSDto()
        {
            PositionId = p12.PositionId,
            PositionName = p12.Position != null ? p12.Position.Name : string.Empty,
            TaskId = p12.TaskId,
            Id = p12.Id
        };
        
        private static Position funcMain1(Never p4, Position p5, TaskPositionSDto p2)
        {
            Position result = p5 ?? new Position();
            
            result.Name = p2.PositionName;
            result.Id = p2.PositionId;
            return result;
            
        }
        
        private static Task funcMain2(Never p6, Task p7, TaskPositionSDto p2)
        {
            Task result = p7 ?? new Task();
            
            result.Id = p2.TaskId;
            return result;
            
        }
    }
}