<?php
// Setup Test Admin User
require_once __DIR__ . '/app/core/Database.php';

try {
    $pdo = Database::connection();
    
    // Check if roles exist, if not create them
    $roleCheck = $pdo->query("SELECT COUNT(*) FROM roles");
    $roleCount = $roleCheck->fetchColumn();
    
    if ($roleCount == 0) {
        $pdo->exec("INSERT INTO roles (name, description) VALUES ('Admin', 'Administrator with full access')");
        $pdo->exec("INSERT INTO roles (name, description) VALUES ('User', 'Regular user with limited access')");
        echo "✓ Roles created<br>";
    }
    
    // Check if admin user already exists
    $userCheck = $pdo->prepare("SELECT id FROM users WHERE email = ?");
    $userCheck->execute(['admin@balorpfinishes.com']);
    
    if ($userCheck->rowCount() == 0) {
        // Create test admin user
        $passwordHash = '$2y$10$XMyHBL1k.UBRGGUsbxTdl.AC7KV8Iu/9kB1x9NNRuzVxHv82DsHu2'; // admin123
        
        $stmt = $pdo->prepare("
            INSERT INTO users (role_id, name, email, password_hash, phone, status)
            VALUES (1, 'Admin User', 'admin@balorpfinishes.com', ?, '+233240000000', 'Active')
        ");
        $stmt->execute([$passwordHash]);
        echo "✓ Admin user created<br>";
        echo "<strong>Login Credentials:</strong><br>";
        echo "Email: admin@balorpfinishes.com<br>";
        echo "Password: admin123<br>";
    } else {
        echo "✓ Admin user already exists<br>";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>
