<?php
include 'db_connect.php';

$governorate = $_GET['governorate'] ?? '';
$specialty = $_GET['specialty'] ?? '';
$name = $_GET['name'] ?? '';

$sql = "SELECT d.*, s.specialty_name_ar 
        FROM doctors d 
        JOIN specialties s ON d.specialty_id = s.id 
        WHERE 1=1";

if ($governorate != '') {
    $sql .= " AND d.governorate LIKE '%$governorate%'";
}
if ($specialty != '') {
    $sql .= " AND s.specialty_name_ar LIKE '%$specialty%'";
}
if ($name != '') {
    $sql .= " AND d.full_name LIKE '%$name%'";
}

$result = mysqli_query($conn, $sql);
$doctors = [];

while($row = mysqli_fetch_assoc($result)) {
    $doctors[] = $row;
}

echo json_encode($doctors);
?>