<?php
session_start();
include 'session.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['plan_id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid request']);
    exit;
}

$plan_id = intval($_POST['plan_id']);

// Get plan details
$query = "SELECT * FROM trading_bot_plans WHERE id = '$plan_id' AND is_active = 1";
$result = mysqli_query($conn, $query);

if ($result && mysqli_num_rows($result) > 0) {
    $plan = mysqli_fetch_assoc($plan);
    
    // Convert boolean values to integers for JSON
    $plan['has_machine_learning'] = intval($plan['has_machine_learning']);
    $plan['has_multi_market'] = intval($plan['has_multi_market']);
    $plan['has_strategy_blending'] = intval($plan['has_strategy_blending']);
    $plan['has_dedicated_manager'] = intval($plan['has_dedicated_manager']);
    $plan['has_api_access'] = intval($plan['has_api_access']);
    
    echo json_encode([
        'success' => true,
        'data' => $plan
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Plan not found or inactive'
    ]);
}
?>