<?php
declare(strict_types=1);

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../app/Services/RankingService.php';

header('Content-Type: application/json; charset=utf-8');

try {
    $db = getDbConnection();
    $service = new RankingService($db);

    $data = $service->getRankingPageData(
        studentId: 1,
        academicYearId: 1,
        period: 'school_year',
        province: null,
        bookLevelId: null
    );

    echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} catch (Throwable $e) {
    http_response_code(500);

    echo json_encode([
        'success' => false,
        'error' => $e->getMessage(),
        'file' => $e->getFile(),
        'line' => $e->getLine(),
    ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
