namespace Netina.Repository.Handlers.ProductCategories;

public class GetProductCategoryQueryHandler(IRepositoryWrapper repositoryWrapper)
    : IRequestHandler<GetProductCategoryQuery, ProductCategoryLDto>
{
    public async Task<ProductCategoryLDto> Handle(GetProductCategoryQuery request, CancellationToken cancellationToken)
    {
        var ent = await repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking
            .Where(b => b.Id == request.Id)
            .Select(ProductCategoryMapper.ProjectToLDto)
            .FirstOrDefaultAsync(cancellationToken);
        if (ent == null)
            throw new AppException("ProductCategory not found", ApiResultStatusCode.NotFound);

        //ent.

        return ent;
    }
}