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

namespace Brizco.Domain.Mappers
{
    public static partial class TaskShiftMapper
    {
        public static TaskShift AdaptToTaskShift(this TaskShiftSDto p1)
        {
            return p1 == null ? null : new TaskShift()
            {
                TaskId = p1.TaskId,
                Task = new Task()
                {
                    Title = p1.TaskTitle,
                    Id = p1.TaskId
                },
                ShiftId = p1.ShiftId,
                Shift = new Shift() {Id = p1.ShiftId},
                Id = p1.Id
            };
        }
        public static TaskShift AdaptTo(this TaskShiftSDto p2, TaskShift p3)
        {
            if (p2 == null)
            {
                return null;
            }
            TaskShift result = p3 ?? new TaskShift();
            
            result.TaskId = p2.TaskId;
            result.Task = funcMain1(new Never(), result.Task, p2);
            result.ShiftId = p2.ShiftId;
            result.Shift = funcMain2(new Never(), result.Shift, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<TaskShiftSDto, TaskShift>> ProjectToTaskShift => p8 => new TaskShift()
        {
            TaskId = p8.TaskId,
            Task = new Task()
            {
                Title = p8.TaskTitle,
                Id = p8.TaskId
            },
            ShiftId = p8.ShiftId,
            Shift = new Shift() {Id = p8.ShiftId},
            Id = p8.Id
        };
        public static TaskShiftSDto AdaptToSDto(this TaskShift p9)
        {
            return p9 == null ? null : new TaskShiftSDto()
            {
                ShiftId = p9.ShiftId,
                ShiftName = p9.Shift != null ? p9.Shift.Title : string.Empty,
                TaskId = p9.TaskId,
                TaskTitle = p9.Task != null ? p9.Task.Title : string.Empty,
                Id = p9.Id
            };
        }
        public static TaskShiftSDto AdaptTo(this TaskShift p10, TaskShiftSDto p11)
        {
            if (p10 == null)
            {
                return null;
            }
            TaskShiftSDto result = p11 ?? new TaskShiftSDto();
            
            result.ShiftId = p10.ShiftId;
            result.ShiftName = p10.Shift != null ? p10.Shift.Title : string.Empty;
            result.TaskId = p10.TaskId;
            result.TaskTitle = p10.Task != null ? p10.Task.Title : string.Empty;
            result.Id = p10.Id;
            return result;
            
        }
        public static Expression<Func<TaskShift, TaskShiftSDto>> ProjectToSDto => p12 => new TaskShiftSDto()
        {
            ShiftId = p12.ShiftId,
            ShiftName = p12.Shift != null ? p12.Shift.Title : string.Empty,
            TaskId = p12.TaskId,
            TaskTitle = p12.Task != null ? p12.Task.Title : string.Empty,
            Id = p12.Id
        };
        
        private static Task funcMain1(Never p4, Task p5, TaskShiftSDto p2)
        {
            Task result = p5 ?? new Task();
            
            result.Title = p2.TaskTitle;
            result.Id = p2.TaskId;
            return result;
            
        }
        
        private static Shift funcMain2(Never p6, Shift p7, TaskShiftSDto p2)
        {
            Shift result = p7 ?? new Shift();
            
            result.Id = p2.ShiftId;
            return result;
            
        }
    }
}