using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Admin.Abstractions;
using Knot.Modules.Admin.Application.Admin.DTOs;
using Knot.Shared.Kernel.Services;
using MediatR;

namespace Knot.Modules.Admin.Application.Admin.Queries;

public record GetDashboardStatsQuery() : IQuery<DashboardStatsDto>;

internal sealed class GetDashboardStatsQueryHandler : IQueryHandler<GetDashboardStatsQuery, DashboardStatsDto>
{
    private readonly IStatisticsService _statisticsService;

    public GetDashboardStatsQueryHandler(IStatisticsService statisticsService)
    {
        _statisticsService = statisticsService;
    }

    public async Task<Result<DashboardStatsDto>> Handle(GetDashboardStatsQuery request, CancellationToken cancellationToken)
    {
        var stats = await _statisticsService.GetDashboardStatsAsync(cancellationToken);
        return Result.Success(stats);
    }
}
