namespace Brizco.Repository.Handlers.ShiftPlan;

public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftPlanQuery, ShiftPlanLDto>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetShiftPlanQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<ShiftPlanLDto> Handle(GetShiftPlanQuery request, CancellationToken cancellationToken)
    {
        var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.ShiftPlan>()
            .TableNoTracking
            .Where(s => s.Id == request.Id)
            .Select(ShiftPlanMapper.ProjectToLDto)
            .FirstOrDefaultAsync(cancellationToken);
        if (shiftPlan == null)
            throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
        return shiftPlan;
    }
}