<?php
header("Content-Type: application/json");
require("../includes/config.php");

try {
    $stmt = $pdo->query("
        SELECT 
            s.id,
            s.subject_name,
            s.class_id,
            s.theory_max,      -- For display and edit
            s.practical_max,   -- For display and edit
            s.pass_marks,      -- For display and edit
            s.status,
            c.class_name
        FROM subjects s
        JOIN classes c ON s.class_id = c.id
        ORDER BY s.id DESC
    ");

    $subjects = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($subjects);

} catch (Exception $e) {
    echo json_encode(["status" => "error", "message" => $e->getMessage()]);
}
?>