using Brizco.Domain.Dtos.LargDtos;

namespace Brizco.Repository.Handlers.Activity;

public class GetActivityQueryHandler : IRequestHandler<GetActivityQuery, ActivityLDto>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetActivityQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }

    public async Task<ActivityLDto> Handle(GetActivityQuery request, CancellationToken cancellationToken)
    {
        var task = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>()
            .TableNoTracking
            .Where(s => s.Id == request.Id)
            .Select(ActivityMapper.ProjectToLDto)
            .FirstOrDefaultAsync(cancellationToken);
        if (task == null)
            throw new AppException("Task not found", ApiResultStatusCode.NotFound);
        return task;
    }
}