using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Knot.Shared.Kernel;
using Knot.Contracts.Settings.Application.Abstractions;
using Knot.Contracts.Settings.Application.DTOs;

namespace Knot.Modules.Settings.Application.Settings.Queries;

public record GetPublicConfigQuery() : IQuery<SystemSettingsDto>;

internal sealed class GetPublicConfigQueryHandler : IQueryHandler<GetPublicConfigQuery, SystemSettingsDto>
{
    private readonly ISettingsService _settings;

    public GetPublicConfigQueryHandler(ISettingsService settings)
    {
        _settings = settings;
    }

    public Task<Result<SystemSettingsDto>> Handle(GetPublicConfigQuery request, CancellationToken cancellationToken)
    {
        return Task.FromResult(Result.Success(_settings.Current));
    }
}
