<?php
require __DIR__ . '/../vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->safeLoad();

use App\Database;

$pdo = Database::getConnection();

$patients = [
  ['national_id'=>'10000000001','first_name'=>'Ahmet','last_name'=>'Yılmaz','birth_date'=>'1984-03-12','gender'=>'male','blood_type'=>'A Rh(+)','phone'=>'0532 111 11 11','email'=>'ahmet.yilmaz@example.com','address'=>'Ataköy Mah. 12. Sk. No:5','city'=>'İstanbul','district'=>'Bakırköy','service_needed'=>1,'notes'=>'Diyaliz günleri: Pzt/Per/Cum'],
  ['national_id'=>'10000000002','first_name'=>'Ayşe','last_name'=>'Demir','birth_date'=>'1990-07-25','gender'=>'female','blood_type'=>'O Rh(+)','phone'=>'0533 222 22 22','email'=>'ayse.demir@example.com','address'=>'Kızılay Mah. 24. Sk. No:8','city'=>'Ankara','district'=>'Çankaya','service_needed'=>0,'notes'=>'Hipertansiyon öyküsü'],
  ['national_id'=>'10000000003','first_name'=>'Mehmet','last_name'=>'Kara','birth_date'=>'1978-11-02','gender'=>'male','blood_type'=>'B Rh(+)','phone'=>'0544 333 33 33','email'=>'mehmet.kara@example.com','address'=>'Alsancak 1403 Sk. No:10','city'=>'İzmir','district'=>'Konak','service_needed'=>1,'notes'=>'Periton diyaliz geçmişi'],
  ['national_id'=>'10000000004','first_name'=>'Fatma','last_name'=>'Çelik','birth_date'=>'1988-02-19','gender'=>'female','blood_type'=>'AB Rh(-)','phone'=>'0505 444 44 44','email'=>'fatma.celik@example.com','address'=>'Nilüfer FSM Bulv. No:45','city'=>'Bursa','district'=>'Nilüfer','service_needed'=>0,'notes'=>'Demir takibi gerekli'],
  ['national_id'=>'10000000005','first_name'=>'Emre','last_name'=>'Şahin','birth_date'=>'1995-09-09','gender'=>'male','blood_type'=>'A Rh(-)','phone'=>'0555 555 55 55','email'=>'emre.sahin@example.com','address'=>'Muratpaşa Işıklar Cad. No:18','city'=>'Antalya','district'=>'Muratpaşa','service_needed'=>1,'notes'=>'Servis güzergahı sahil'],
  ['national_id'=>'10000000006','first_name'=>'Zeynep','last_name'=>'Aydın','birth_date'=>'1982-06-30','gender'=>'female','blood_type'=>'O Rh(-)','phone'=>'0536 666 66 66','email'=>'zeynep.aydin@example.com','address'=>'Kartal Uğur Mumcu Mah.','city'=>'İstanbul','district'=>'Kartal','service_needed'=>0,'notes'=>'Düşük Kt/V, takip'],
  ['national_id'=>'10000000007','first_name'=>'Burak','last_name'=>'Erdoğan','birth_date'=>'1975-12-05','gender'=>'male','blood_type'=>'B Rh(-)','phone'=>'0542 777 77 77','email'=>'burak.erdogan@example.com','address'=>'Etimesgut Elvankent Mah.','city'=>'Ankara','district'=>'Etimesgut','service_needed'=>1,'notes'=>'Diabetik nefropati'],
  ['national_id'=>'10000000008','first_name'=>'Elif','last_name'=>'Koç','birth_date'=>'1993-04-14','gender'=>'female','blood_type'=>'AB Rh(+)','phone'=>'0507 888 88 88','email'=>'elif.koc@example.com','address'=>'Ortahisar Kunduracılar Cd.','city'=>'Trabzon','district'=>'Ortahisar','service_needed'=>0,'notes'=>'Stentli hasta'],
  ['national_id'=>'10000000009','first_name'=>'Can','last_name'=>'Öztürk','birth_date'=>'1986-01-21','gender'=>'male','blood_type'=>'A Rh(+)','phone'=>'0538 999 99 99','email'=>'can.ozturk@example.com','address'=>'Melikgazi İldem Mh.','city'=>'Kayseri','district'=>'Melikgazi','service_needed'=>1,'notes'=>'Akşam seansı uygun'],
  ['national_id'=>'10000000010','first_name'=>'Selin','last_name'=>'Yıldırım','birth_date'=>'1998-08-08','gender'=>'female','blood_type'=>'O Rh(+)','phone'=>'0551 123 45 67','email'=>'selin.yildirim@example.com','address'=>'Karşıyaka Bostanlı Mh.','city'=>'İzmir','district'=>'Karşıyaka','service_needed'=>0,'notes'=>'Vasküler erişim kontrolü']
];

$pdo->beginTransaction();
try {
  $ins = $pdo->prepare('INSERT IGNORE INTO patients (national_id, first_name, last_name, birth_date, gender, blood_type, phone, email, address, city, district, service_needed, notes) VALUES (:national_id,:first_name,:last_name,:birth_date,:gender,:blood_type,:phone,:email,:address,:city,:district,:service_needed,:notes)');
  foreach ($patients as $p) {
    $ins->execute([
      ':national_id' => $p['national_id'],
      ':first_name' => $p['first_name'],
      ':last_name' => $p['last_name'],
      ':birth_date' => $p['birth_date'],
      ':gender' => $p['gender'],
      ':blood_type' => $p['blood_type'],
      ':phone' => $p['phone'],
      ':email' => $p['email'],
      ':address' => $p['address'],
      ':city' => $p['city'],
      ':district' => $p['district'],
      ':service_needed' => $p['service_needed'],
      ':notes' => $p['notes'],
    ]);
  }
  $pdo->commit();
  echo "Seeded " . count($patients) . " patients.\n";
} catch (Throwable $e) {
  if ($pdo->inTransaction()) $pdo->rollBack();
  echo "Seed failed: " . $e->getMessage() . "\n";
}
