<?php
require_once dirname(__DIR__) . '/app/bootstrap.php';
use App\Core\Database;
use App\Core\Security;

header('Content-Type: application/json');

try {
    $users = Database::select("SELECT id, name, email, password, role FROM users");
    $result = [];
    foreach ($users as $u) {
        $decryptedEmail = Security::decrypt($u['email']);
        $result[] = [
            'id' => $u['id'],
            'name' => $u['name'],
            'email' => $decryptedEmail,
            'role' => $u['role'],
            'password_hash' => $u['password']
        ];
    }
    echo json_encode(['status' => 'success', 'users' => $result]);
} catch (\Exception $e) {
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
