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

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

public sealed record GetSettingsQuery() : IQuery<SystemSettingsDto>;

internal sealed class GetSettingsQueryHandler : IQueryHandler<GetSettingsQuery, SystemSettingsDto>
{
    private readonly ISettingsService _settingsService;

    public GetSettingsQueryHandler(ISettingsService settingsService)
    {
        _settingsService = settingsService;
    }

    public async Task<Result<SystemSettingsDto>> Handle(GetSettingsQuery request, CancellationToken cancellationToken)
    {
        var settings = await _settingsService.GetSettingsAsync(cancellationToken);
        return Result.Success(settings);
    }
}
