<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../classes/Payroll.php';

$db = new Database();
$payroll = new Payroll($db->getConnection());

$gradeId = (int)($_GET['grade_id'] ?? 0);
if ($gradeId <= 0) {
    echo json_encode(['error' => 'Invalid grade_id']);
    exit();
}

$grade = $payroll->getGradeById($gradeId);
if (!$grade) {
    echo json_encode(['error' => 'Grade not found']);
    exit();
}

echo json_encode($grade);
