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.GetConfigChangeHistory;

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