<?php
require_once __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();

use App\Database;

$pdo = Database::getConnection();

// Check if any patient exists
$st = $pdo->query("SELECT id FROM patients LIMIT 1");
$patient = $st->fetch();

if ($patient) {
    $pid = $patient['id'];
    echo "Patient ID: $pid\n";
    echo "Edit URL: http://localhost:8000/public/HastaModulu/hastaDuzenle.php?id=$pid\n";
    echo "Detail URL: http://localhost:8000/public/HastaModulu/hastaDetay.php?id=$pid\n";
} else {
    echo "No patients found. Creating test patient...\n";
    $ins = $pdo->prepare('INSERT INTO patients (first_name, last_name, national_id) VALUES (:fn, :ln, :ni)');
    $ins->execute([
        ':fn' => 'Test',
        ':ln' => 'Hasta',
        ':ni' => '12345678901'
    ]);
    $pid = $pdo->lastInsertId();
    
    // Add test relative
    $rel = $pdo->prepare('INSERT INTO patient_relatives (patient_id, relation, full_name, phone) VALUES (:pid, :rel, :name, :phone)');
    $rel->execute([
        ':pid' => $pid,
        ':rel' => 'Eş',
        ':name' => 'Test Eş',
        ':phone' => '555-1234'
    ]);
    
    echo "Test patient created with ID: $pid\n";
    echo "Edit URL: http://localhost:8000/public/HastaModulu/hastaDuzenle.php?id=$pid\n";
}
?>
