<?php
/**
 * Create System Admin User - Standalone script
 * Run this once to create a system admin user
 * DELETE this file after use for security
 */

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

$username = 'sysadmin';
$password = 'sysadmin123';
$fullName = 'System Administrator';

// Check if user already exists
$stmt = $pdo->prepare('SELECT id FROM users WHERE username = ?');
$stmt->execute([$username]);
if ($stmt->fetch()) {
    die("User '$username' already exists.\n");
}

// Create system admin user
$hash = password_hash($password, PASSWORD_DEFAULT);
try {
    $stmt = $pdo->prepare('INSERT INTO users (username, password, full_name, role, active) VALUES (?, ?, ?, ?, 1)');
    $stmt->execute([$username, $hash, $fullName, 'system_admin']);
    echo "✓ System admin user created successfully!\n";
    echo "Username: $username\n";
    echo "Password: $password\n";
    echo "\n⚠️  IMPORTANT: Change the password after first login!\n";
    echo "⚠️  DELETE this file (create-system-admin.php) for security!\n";
} catch (PDOException $e) {
    die("Error creating user: " . $e->getMessage() . "\n");
}
