<?php
declare(strict_types=1);

if (session_status() === PHP_SESSION_NONE) { session_start(); }
global $pdo;

header('Content-Type: application/json; charset=utf-8');

$id = (int)($_GET['id'] ?? 0);
if ($id <= 0) {
  echo json_encode(['ok'=>false,'error'=>'id yok']);
  exit;
}

try {
  $st = $pdo->prepare("SELECT id, telefon1, telefon2, email FROM hastalar WHERE id=? LIMIT 1");
  $st->execute([$id]);
  $row = $st->fetch(PDO::FETCH_ASSOC);

  if (!$row) {
    echo json_encode(['ok'=>false,'error'=>'hasta bulunamadı']);
    exit;
  }

  echo json_encode(['ok'=>true,'data'=>$row], JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
  echo json_encode(['ok'=>false,'error'=>$e->getMessage()]);
}
