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

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

use App\Database;

$pdo = Database::getConnection();

$institutions = [
  ['name' => 'Anadolu Diyaliz Merkezi', 'type' => 'Özel Diyaliz', 'tax_number' => '1234567890', 'tax_office' => 'Kadıköy VD', 'address' => 'Bağdat Cd. No:120', 'full_address' => 'Bağdat Cd. No:120 Suadiye Kadıköy İstanbul', 'phone' => '0216 555 00 01'],
  ['name' => 'Ege Nefroloji Kliniği', 'type' => 'Klinik', 'tax_number' => '2234567890', 'tax_office' => 'Konak VD', 'address' => 'Cumhuriyet Blv. No:48', 'full_address' => 'Cumhuriyet Blv. No:48 Alsancak Konak İzmir', 'phone' => '0232 555 00 02'],
  ['name' => 'Başkent Tıp Merkezi', 'type' => 'Tıp Merkezi', 'tax_number' => '3234567890', 'tax_office' => 'Çankaya VD', 'address' => 'Tunus Cd. No:87', 'full_address' => 'Tunus Cd. No:87 Kavaklıdere Çankaya Ankara', 'phone' => '0312 555 00 03'],
  ['name' => 'Marmara Böbrek Sağlığı', 'type' => 'Özel Hastane', 'tax_number' => '4234567890', 'tax_office' => 'Üsküdar VD', 'address' => 'Libadiye Cd. No:65', 'full_address' => 'Libadiye Cd. No:65 Altunizade Üsküdar İstanbul', 'phone' => '0216 555 00 04'],
  ['name' => 'Karadeniz Diyaliz', 'type' => 'Özel Diyaliz', 'tax_number' => '5234567890', 'tax_office' => 'Ortahisar VD', 'address' => 'Atapark Mah. Devlet Sahil Yolu', 'full_address' => 'Atapark Mah. Devlet Sahil Yolu No:22 Ortahisar Trabzon', 'phone' => '0462 555 00 05'],
  ['name' => 'Akdeniz Sağlık Grubu', 'type' => 'Hastane', 'tax_number' => '6234567890', 'tax_office' => 'Muratpaşa VD', 'address' => 'Aspendos Blv. No:190', 'full_address' => 'Aspendos Blv. No:190 Muratpaşa Antalya', 'phone' => '0242 555 00 06'],
  ['name' => 'İç Anadolu Diyaliz', 'type' => 'Özel Diyaliz', 'tax_number' => '7234567890', 'tax_office' => 'Kocasinan VD', 'address' => 'Erciyes Cd. No:40', 'full_address' => 'Erciyes Cd. No:40 Kocasinan Kayseri', 'phone' => '0352 555 00 07'],
  ['name' => 'Güneydoğu Renal Bakım', 'type' => 'Merkez', 'tax_number' => '8234567890', 'tax_office' => 'Şehitkamil VD', 'address' => 'İbrahimli Mah. 15 Nolu Cd.', 'full_address' => 'İbrahimli Mah. 15 Nolu Cd. No:18 Şehitkamil Gaziantep', 'phone' => '0342 555 00 08'],
  ['name' => 'Trakya Nefroloji Enstitüsü', 'type' => 'Araştırma', 'tax_number' => '9234567890', 'tax_office' => 'Edirne VD', 'address' => 'Talatpaşa Cd. No:22', 'full_address' => 'Talatpaşa Cd. No:22 Merkez Edirne', 'phone' => '0284 555 00 09'],
  ['name' => 'Ege Renal Destek', 'type' => 'Klinik', 'tax_number' => '10345678901', 'tax_office' => 'Bornova VD', 'address' => 'Kazım Dirik Mah. 296 Sk.', 'full_address' => 'Kazım Dirik Mah. 296 Sk. No:14 Bornova İzmir', 'phone' => '0232 555 00 10']
];

$pdo->beginTransaction();
try {
  $insert = $pdo->prepare('INSERT IGNORE INTO institutions (name, type, tax_number, tax_office, address, full_address, phone) VALUES (:name, :type, :tax_number, :tax_office, :address, :full_address, :phone)');
  foreach ($institutions as $i) {
    $insert->execute([
      ':name' => $i['name'],
      ':type' => $i['type'],
      ':tax_number' => $i['tax_number'],
      ':tax_office' => $i['tax_office'],
      ':address' => $i['address'],
      ':full_address' => $i['full_address'],
      ':phone' => $i['phone']
    ]);
  }
  $pdo->commit();
  echo 'Seeded ' . count($institutions) . " institutions.\n";
} catch (Throwable $e) {
  if ($pdo->inTransaction()) {
    $pdo->rollBack();
  }
  echo 'Seed failed: ' . $e->getMessage() . "\n";
}
