<?php
require_once 'config.php';

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

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['success' => false, 'message' => 'Method not allowed']);
    exit;
}

$network_type = $_POST['network_type'] ?? 'mtn';

// Validate network type (MTN only)
if ($network_type !== 'mtn') {
    echo json_encode(['success' => false, 'message' => 'Invalid network type. Only MTN is supported.']);
    exit;
}

// Fetch packages from database
$packages_query = "SELECT package_name, price FROM customer_packages WHERE network_type = ? AND is_active = 1 ORDER BY sort_order";
$stmt = $conn->prepare($packages_query);
$stmt->bind_param("s", $network_type);
$stmt->execute();
$result = $stmt->get_result();

$packages = [];
while ($row = $result->fetch_assoc()) {
    $packages[$row['package_name']] = floatval($row['price']);
}
$stmt->close();

echo json_encode(['success' => true, 'packages' => $packages]);
?>
