using Task = Brizco.Domain.Entities.Task.Task;

namespace Brizco.Domain;

public class MapsterRegister : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<Task, TaskSDto>()
            .Map("SetFor",o=>DateTimeExtensions.DateTimeToUnixTimeStamp(o.SetFor))
            .Map("Shifts", o => o.Shifts.Select(d => d.Shift != null ? d.Shift.Title : string.Empty))
            .Map("Routines", o => o.Routines.Select(d => d.Routine != null ? d.Routine.Name : string.Empty))
            .Map("Positions", o => o.Positions.Select(d => d.Position != null ? d.Position.Name : string.Empty))
            .TwoWays();

        config.NewConfig<TaskShift, TaskShiftSDto>()
            .Map("ShiftName", o => o.Shift != null ? o.Shift.Title : string.Empty)
            .Map("TaskTitle", o => o.Task != null ? o.Task.Title : string.Empty)
            .TwoWays();

        config.NewConfig<TaskPosition, TaskPositionSDto>()
            .Map("PositionName", o => o.Position != null ? o.Position.Name : string.Empty)
            .TwoWays();

        config.NewConfig<Activity, ActivitySDto>()
            .Map("UserFirstName", o => o.User !=null ? o.User.FirstName : string.Empty)
            .Map("UserLastName", o => o.User != null ? o.User.LastName : string.Empty)
            .Map("ShiftTitle",o=>o.Shift != null ? o.Shift.Title : string.Empty)
            .TwoWays();

        config.NewConfig<Task, TaskLDto>()
            .Map("SetFor", o => DateTimeExtensions.DateTimeToUnixTimeStamp(o.SetFor))
            .TwoWays();

        config.NewConfig<Shift, ShiftSDto>()
            .Map("Days",o=>o.Days.Select(d=>d.DayOfWeek).ToList())
            .TwoWays();

        config.NewConfig<Shift, ShiftLDto>()
            .Map("Days", o => o.Days.Select(d => d.DayOfWeek).ToList())
            .TwoWays();

        config.NewConfig<ShiftPlan, ShiftPlanLDto>()
            .Map("SupervisorFullName", o => o.Supervisor != null ? o.Supervisor.FirstName + " " + o.Supervisor.LastName : string.Empty)
            .TwoWays();

        config.NewConfig<ShiftPlanUser, ShiftPlanUserSDto>()
            .Map("UserFullName", o => o.User != null ? o.User.FirstName + " " + o.User.LastName : string.Empty)
            .Map("PositionName", o => o.Position != null ? o.Position.Name : string.Empty)
            .TwoWays();

        config.NewConfig<ComplexUserRole, ComplexUserRoleSDto>()
            .Map("RoleName", org => org.Role!.PersianName)
            .TwoWays();

        config.NewConfig<Position, PositionLDto>()
            .Map("SectionName", org => org.Section != null ? org.Section.Name : string.Empty)
            .TwoWays();

        config.NewConfig<ComplexUser, ComplexUserSDto>()
            .Map("ComplexName", o=>o.Complex!=null ? o.Complex.Name : string.Empty)
            .Map("FirstName", o=>o.User!=null ? o.User.FirstName : string.Empty)
            .Map("LastName", o=>o.User!=null ? o.User.LastName : string.Empty)
            .Map("NationalId", o=>o.User!=null ? o.User.NationalId : string.Empty)
            .TwoWays();
    }
}