<?php

declare(strict_types=1);

namespace ImovelZapAi\Conversations\Application\Queries;

use Illuminate\Support\Collection;
use ImovelZapAi\Conversations\Domain\Enums\HandoffStatus;
use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\HumanHandoffModel;

final class HandoffQueueQuery
{
    /**
     * @return Collection<int, HumanHandoffModel>
     */
    public function waiting(int $limit = 50): Collection
    {
        return HumanHandoffModel::query()
            ->where('status', HandoffStatus::Waiting)
            ->with(['contact', 'summary', 'leadScore', 'conversation'])
            ->orderByDesc('priority_score')
            ->orderBy('queued_at')
            ->limit($limit)
            ->get();
    }
}
