using Baya.Application.Common;
using Baya.Application.Contracts.Configuration;
using Baya.Application.Models.Common;
using Baya.Application.Models.Configuration;
using Mediator;

namespace Baya.Application.Features.Configuration.Queries.ListPlatformConfigs;

internal sealed class ListPlatformConfigsQueryHandler(IPlatformConfig platformConfig)
    : IRequestHandler<ListPlatformConfigsQuery, OperationResult<PagedResult<PlatformConfigDto>>>
{
    public async ValueTask<OperationResult<PagedResult<PlatformConfigDto>>> Handle(ListPlatformConfigsQuery request, CancellationToken cancellationToken)
    {
        var (page, pageSize) = Pagination.Normalize(request.Page, request.PageSize);
        var result = await platformConfig.ListAsync(page, pageSize, cancellationToken);
        return OperationResult<PagedResult<PlatformConfigDto>>.SuccessResult(result);
    }
}
