<?php
header('Content-Type: application/json');
session_start();
include '../layouts/dbconn.php';

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['success' => false, 'message' => 'Not authenticated']);
    exit();
}

try {
    // Get consultation department
    $dept_sql = "SELECT department_id, department_name, department_code 
                 FROM departments 
                 WHERE department_code = 'CONSULTATION' AND is_active = 1
                 LIMIT 1";
    $result = $conn->query($dept_sql);
    
    if ($result->num_rows > 0) {
        $dept = $result->fetch_assoc();
        echo json_encode([
            'success' => true,
            'department_id' => $dept['department_id'],
            'department_name' => $dept['department_name'],
            'department_code' => $dept['department_code']
        ]);
    } else {
        echo json_encode([
            'success' => false,
            'message' => 'Consultation department not found'
        ]);
    }
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => $e->getMessage()
    ]);
}

if (isset($conn)) {
    $conn->close();
}
?>
