<?php
// ============================================================
//  ajax/get_article_types.php  —  Article types for a specialty
// ============================================================
require_once __DIR__ . '/../config/db.php';
header('Content-Type: application/json');

$specialtyId = (int)($_GET['specialty_id'] ?? 0);
if (!$specialtyId) jsonResponse(false, 'Specialty ID required');

try {
    $stmt = db()->prepare(
        "SELECT * FROM article_types WHERE specialty_id = ? ORDER BY display_order, name"
    );
    $stmt->execute([$specialtyId]);
    jsonResponse(true, '', ['article_types' => $stmt->fetchAll()]);
} catch (PDOException $e) {
    jsonResponse(false, 'DB error: ' . $e->getMessage());
}