<?php
ob_start();
session_start();
header('Content-Type: application/json; charset=utf-8');

if (!isset($_SESSION['username'])) {
    http_response_code(401);
    echo json_encode(['success' => false, 'msg' => 'Unauthorized']);
    exit;
}

require_once __DIR__ . '/../includ/db.php';
require_once __DIR__ . '/../includ/plan_helpers.php';

$serverId = (int) ($_GET['server_id'] ?? $_POST['server_id'] ?? 0);
if ($serverId <= 0) {
    echo json_encode(['success' => false, 'msg' => 'server_id required', 'inbounds' => []]);
    exit;
}

PlanInboundHelper::ensureSchema($conn);
$inbounds = PlanInboundHelper::listInbounds($conn, $serverId);
echo json_encode(['success' => true, 'inbounds' => $inbounds], JSON_UNESCAPED_UNICODE);
