#!/usr/bin/env php
<?php
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/functions.php';

$pdo = getPDO();

$username = 'kdorine';
$nom = 'KOUAME DORINE';
$email = 'dorine.kouame@ciberci.com';
$password = 'CIBER@2026';
$hash = password_hash($password, PASSWORD_BCRYPT);

$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
    echo "Le superadmin existe déjà.\n";
    exit;
}

$stmt = $pdo->prepare("INSERT INTO users (username, nom, email, password_hash, role) VALUES (?, ?, ?, ?, 'superadmin')");
$stmt->execute([$username, $nom, $email, $hash]);
$userId = $pdo->lastInsertId();
savePasswordHistory($pdo, $userId, $hash);
echo "Superadmin créé.\n";