using Managing.Application.Abstractions.Repositories;
using Managing.Application.ManageBot.Commands;
using Managing.Domain.Statistics;
using MediatR;

namespace Managing.Application.ManageBot
{
    /// <summary>
    /// Handler for retrieving paginated agent summaries with sorting and filtering
    /// </summary>
    public class GetPaginatedAgentSummariesCommandHandler : IRequestHandler<GetPaginatedAgentSummariesCommand,
        (IEnumerable<AgentSummary> Results, int TotalCount)>
    {
        private readonly IAgentSummaryRepository _agentSummaryRepository;

        public GetPaginatedAgentSummariesCommandHandler(IAgentSummaryRepository agentSummaryRepository)
        {
            _agentSummaryRepository = agentSummaryRepository;
        }

        public async Task<(IEnumerable<AgentSummary> Results, int TotalCount)> Handle(
            GetPaginatedAgentSummariesCommand request,
            CancellationToken cancellationToken)
        {
            return await _agentSummaryRepository.GetPaginatedAsync(
                request.Page,
                request.PageSize,
                request.SortBy,
                request.SortOrder,
                request.AgentNames);
        }
    }
} 