// EN: Handler for GetQueueStatsQuery.
// VI: Handler cho GetQueueStatsQuery.

using MediatR;
using FnbEngine.Domain.AggregatesModel.BaristaAggregate;

namespace FnbEngine.API.Application.Queries;

/// <summary>
/// EN: Handler for getting queue statistics for a shop.
/// VI: Handler de lay thong ke hang doi cho shop.
/// </summary>
public class GetQueueStatsQueryHandler : IRequestHandler<GetQueueStatsQuery, QueueStatsDto>
{
    private readonly IBaristaQueueRepository _repository;

    public GetQueueStatsQueryHandler(IBaristaQueueRepository repository)
    {
        _repository = repository ?? throw new ArgumentNullException(nameof(repository));
    }

    public async Task<QueueStatsDto> Handle(GetQueueStatsQuery request, CancellationToken cancellationToken)
    {
        var stats = await _repository.GetStatsAsync(request.ShopId, cancellationToken);

        return new QueueStatsDto(
            stats.TotalQueued,
            stats.TotalPreparing,
            stats.TotalReady,
            stats.TotalDelivered,
            stats.TotalCancelled,
            stats.AveragePrepTimeMinutes);
    }
}
