using Brizco.Domain.Entities.Complex;
using Brizco.Domain.Entities.Shift;
using Mapster;
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<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<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();
    }
}