<?php
require_once 'db/config.php';
try {
    $db = db();
    echo "Testing role_groups insert...\n";
    $stmt = $db->prepare("INSERT INTO role_groups (name, permissions) VALUES (?, ?)");
    $stmt->execute(['Test Group', json_encode(['dashboard_view'])]);
    $groupId = $db->lastInsertId();
    echo "Inserted Group ID: $groupId\n";

    echo "Testing users insert...\n";
    $stmt = $db->prepare("INSERT INTO users (username, password, email, group_id) VALUES (?, ?, ?, ?)");
    $stmt->execute(['testuser_' . time(), password_hash('password', PASSWORD_DEFAULT), 'test@example.com', $groupId]);
    echo "Inserted User ID: " . $db->lastInsertId() . "\n";

    echo "Cleanup...\n";
    $db->prepare("DELETE FROM users WHERE username LIKE 'testuser_%'")->execute();
    $db->prepare("DELETE FROM role_groups WHERE name = 'Test Group'")->execute();
    echo "Done.\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
