namespace CMSMicroservice.Application.UserWalletHistoryCQ.Queries.GetUserWalletHistory;
public class GetUserWalletHistoryQueryHandler : IRequestHandler<GetUserWalletHistoryQuery, GetUserWalletHistoryResponseDto>
{
    private readonly IApplicationDbContext _context;

    public GetUserWalletHistoryQueryHandler(IApplicationDbContext context)
    {
        _context = context;
    }

    public async Task<GetUserWalletHistoryResponseDto> Handle(GetUserWalletHistoryQuery request,
        CancellationToken cancellationToken)
    {
        var response = await _context.UserWalletHistories
            .AsNoTracking()
            .Where(x => x.Id == request.Id)
            .ProjectToType<GetUserWalletHistoryResponseDto>()
            .FirstOrDefaultAsync(cancellationToken);

        return response ?? throw new NotFoundException(nameof(UserWalletHistory), request.Id);
    }
}
