<?php
/**
 * Run once to create your first Super Admin login:
 *   php database/seed_superadmin.php admin admin@hammerheadsecurity.com YourStrongPassword123
 */
require __DIR__ . '/../config/autoload.php';

use App\Core\Database;

[$script, $username, $email, $password] = array_pad($argv, 4, null);

if (!$username || !$email || !$password) {
    echo "Usage: php seed_superadmin.php <username> <email> <password>\n";
    exit(1);
}

$db = Database::connection();
$hash = password_hash($password, PASSWORD_DEFAULT);

$stmt = $db->prepare(
    "INSERT INTO superadmins (username, password_hash, email, full_name, created_at)
     VALUES (:u, :p, :e, :n, NOW())
     ON DUPLICATE KEY UPDATE password_hash = :p2"
);
$stmt->execute([
    'u' => $username, 'p' => $hash, 'e' => $email,
    'n' => 'Super Administrator', 'p2' => $hash,
]);

echo "Super Admin '{$username}' created/updated successfully.\n";
