<?php

declare(strict_types=1);

/**
 * bin/seed.php
 *
 * Usage: php bin/seed.php
 *
 * Runs every seeder in database/seeders/ in dependency order (see
 * DatabaseSeeder::SEEDERS). Always run `php bin/migrate.php` first —
 * this assumes the schema already exists.
 */

require __DIR__ . '/../app/Core/Autoloader.php';

use App\Core\Autoloader;
use App\Core\Database;
use App\Core\Env;
use Database\Seeders\DatabaseSeeder;

Autoloader::register(dirname(__DIR__));
Env::load(dirname(__DIR__) . '/.env');

echo "Seeding A&B Hub database...\n\n";

$pdo = Database::connection();
$pdo->beginTransaction();

try {
    (new DatabaseSeeder())->run($pdo);
    $pdo->commit();
    echo "✔ Seeding complete.\n";
} catch (\Throwable $e) {
    $pdo->rollBack();
    echo "✘ Seeding failed, rolled back: {$e->getMessage()}\n";
    echo $e->getTraceAsString() . "\n";
    exit(1);
}
