<?php
// =============================================================
//  GET /api/v1/rotations/student_eligible
//
//  Clinical students eligible to be selected into a NEW rotation-
//  generation batch — the population POST /rotations/student_generate
//  can actually act on. Same reasoning as nurse_eligible.php: not
//  rotations/student_list.php, which INNER JOINs student_rotation_details
//  and so excludes anyone without a rotation yet. Mirrors
//  app/create_clinical_rotation.php's own lookup query field-for-field.
// =============================================================

require_once __DIR__ . '/../_bootstrap.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    Api::error(405, 'MethodNotAllowed', 'Use GET');
}

api_authenticate();
api_require_permission('assign_rotations');

$result = $conn->query("
    SELECT id, firstname, surname, student_id,
           school_name, level, programme
    FROM clinical_students
    WHERE status = 'Active' AND rotation_status = 'Not_started'
    ORDER BY school_name, firstname, surname
");

Api::success(['students' => $result->fetch_all(MYSQLI_ASSOC)]);
