<?php
/**
 * Jalankan sekali untuk membuat akun admin pertama:
 *   php database/seed_admin.php
 *
 * Password di-hash dengan password_hash() (bcrypt) agar aman,
 * bukan disimpan sebagai teks biasa di file .sql.
 */

require_once __DIR__ . '/../config/config.php';

use App\Core\Database;

spl_autoload_register(function (string $class): void {
    $prefix = 'App\\';
    if (str_starts_with($class, $prefix)) {
        $file = BASE_PATH . '/app/' . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
        if (file_exists($file)) {
            require $file;
        }
    }
});

$nama     = 'Administrator';
$username = 'admin';
$email    = 'admin@fasilkom.ac.id';
$password = 'admin123'; // WAJIB diganti setelah login pertama kali

$hash = password_hash($password, PASSWORD_BCRYPT);

$db = Database::connect();
$stmt = $db->prepare(
    "INSERT INTO admin_users (nama, username, email, password, role) VALUES (:nama, :username, :email, :password, 'super_admin')"
);
$stmt->execute([
    'nama'     => $nama,
    'username' => $username,
    'email'    => $email,
    'password' => $hash,
]);

echo "Akun admin berhasil dibuat.\n";
echo "Username: {$username}\n";
echo "Password: {$password} (segera ganti setelah login)\n";
