<?php
namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

class AIReviewerController extends Controller
{
    public function suggest($submissionId)
    {
        RoleGuard::allow(['org_admin','tpc']);

        $db = Database::getInstance();
        $orgId = $_SESSION['user']['org_id'];

        $reviewers = $db->prepare("
            SELECT u.id,
            COUNT(sr.id) as load_count
            FROM users u
            LEFT JOIN submission_reviewers sr
            ON sr.reviewer_id = u.id
            WHERE u.role='reviewer'
            AND u.org_id=?
            GROUP BY u.id
            ORDER BY load_count ASC
            LIMIT 3
        ");
        $reviewers->execute([$orgId]);

        echo json_encode($reviewers->fetchAll());
    }
}
