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

namespace Baya.Application.Features.Configuration.Commands.UpdatePlatformConfig;

internal sealed class UpdatePlatformConfigCommandHandler(IPlatformConfig platformConfig)
    : IRequestHandler<UpdatePlatformConfigCommand, OperationResult<bool>>
{
    public async ValueTask<OperationResult<bool>> Handle(UpdatePlatformConfigCommand request, CancellationToken cancellationToken)
    {
        var updated = await platformConfig.SetConfig(request.Key, request.Value, cancellationToken);

        return updated
            ? OperationResult<bool>.SuccessResult(true)
            : OperationResult<bool>.NotFoundResult($"Config key '{request.Key}' does not exist.");
    }
}
