<?php
require_once __DIR__ . '/../admin_middleware.php';

// Requires 'manage_users' (or make it Super Admin only in middleware logic)
verifyAdmin('manage_users');

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

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    exit;
}

$data = json_decode(file_get_contents("php://input"), true);
$target_id = $data['user_id'];

try {
    $stmt = $pdo->prepare("DELETE FROM i_users WHERE iuid = ?");
    $stmt->execute([$target_id]);

    echo json_encode(['success' => true, 'message' => 'User deleted']);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}
?>
