namespace Netina.Repository.Handlers.Faqs;

public class GetFaqsQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper)
    : IRequestHandler<GetFaqsQuery, List<BaseFaq>>
{
    public async Task<List<BaseFaq>> Handle(GetFaqsQuery request, CancellationToken cancellationToken)
    {
        var count = request.Count > 0 ? request.Count : 20;
        if (count > 50)
            throw new BaseApiException(ApiResultStatusCode.BadRequest, "Count limit is 50");
        var response = await martenRepositoryWrapper.SetRepository<BaseFaq>()
            .GetEntitiesAsync(request.Page, count, cancellationToken);
        response.ForEach(f => { f.Faqs ??= new Dictionary<string, string>(); });
        return response;
    }
}