using Brizco.Domain.Entities.Shift;

namespace Brizco.Repository.Handlers.Shift;

public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftQuery, ShiftLDto>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetShiftPlanQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<ShiftLDto> Handle(GetShiftQuery request, CancellationToken cancellationToken)
    {
        var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
            .TableNoTracking
            .Where(s => s.Id == request.Id)
            .Select(ShiftMapper.ProjectToLDto)
            .FirstOrDefaultAsync(cancellationToken);

        if (shift == null)
            throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
        //var shiftDays = await _repositoryWrapper.SetRepository<ShiftDay>()
        //    .TableNoTracking
        //    .Where(sd => sd.ShiftId == request.Id)
        //    .ToListAsync(cancellationToken);
        //shift.Days = shiftDays.Select(s => s.DayOfWeek).ToList();

        return shift;
    }
}