<?php
header('Content-Type: application/json');
require_once('../libs/classes/DbPathsArray.php');
require_once('../libs/classes/App_DB.php');

$db = new App_DB(DBU::$dba_user);

$response = [
    'success' => false,
    'message' => '',
    'totalMarks' => 0
];

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $subjectSno = $_GET['subject_sno'] ?? '';

    if (empty($subjectSno)) {
        $response['message'] = 'مضمون کا انتخاب ضروری ہے';
        echo json_encode($response);
        exit;
    }

    try {
        $sql = "SELECT totalMarks FROM subjects WHERE sno = :sno";
        $totalMarks = $db->getValue($sql, ['sno' => $subjectSno]);
        
        if ($totalMarks !== false) {
            $response['success'] = true;
            $response['totalMarks'] = (int)$totalMarks;
        } else {
            $response['message'] = 'مضمون نہیں ملا';
        }
    } catch (Exception $e) {
        $response['message'] = 'ڈیٹابیس کی خرابی: ' . $e->getMessage();
    }
}

echo json_encode($response);
