<?php
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
include_once 'db_connect.php';

// استقبال البيانات من تطبيق فلاتر
$name_ar = $_POST['name_ar'] ?? '';
$name_en = $_POST['name_en'] ?? '';

if (!empty($name_ar) && !empty($name_en)) {
    try {
        $stmt = $conn->prepare("INSERT INTO medical_specialties (name_ar, name_en, created_at) VALUES (?, ?, NOW())");
        if ($stmt->execute([$name_ar, $name_en])) {
            echo json_encode([
                "status" => "success",
                "message" => "تم إضافة الاختصاص بنجاح"
            ]);
        } else {
            echo json_encode(["status" => "error", "message" => "فشل تنفيذ الاستعلام"]);
        }
    } catch (Exception $e) {
        echo json_encode(["status" => "error", "message" => $e->getMessage()]);
    }
} else {
    echo json_encode(["status" => "error", "message" => "يرجى ملء جميع الحقول"]);
}
?>