<?php
/**
 * Run this once from your server's command line (SSH / terminal) to create
 * your admin login. It is NOT reachable over HTTP — there's no route to it
 * from api/ or admin/, and it refuses to run if invoked any other way.
 *
 * Usage:
 *   php create-admin.php yourusername "your strong password"
 */
if (php_sapi_name() !== 'cli') {
    http_response_code(403);
    exit('This script only runs from the command line.');
}

require_once __DIR__ . '/includes/auth.php';

$username = $argv[1] ?? null;
$password = $argv[2] ?? null;

if (!$username || !$password) {
    fwrite(STDERR, "Usage: php create-admin.php <username> <password>\n");
    exit(1);
}
if (strlen($password) < 8) {
    fwrite(STDERR, "Choose a password of at least 8 characters.\n");
    exit(1);
}

create_admin_user($username, $password);
echo "Admin user '{$username}' created/updated. You can now log in at admin/login.php.\n";
