<?php
/**
 * Calculate price for a package in a specific store
 * Used for comparisons and demos
 */

require_once '../config.php';
require_once '../app/classes/StorePricingManager.php';

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

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

$storeId = intval($_POST['store_id'] ?? 0);
$packageSize = $_POST['package_size'] ?? '';
$network = $_POST['network'] ?? 'mtn';

if ($storeId <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid store ID']);
    exit;
}

if (empty($packageSize)) {
    echo json_encode(['success' => false, 'message' => 'Package size required']);
    exit;
}

$pricingManager = new StorePricingManager($conn);
$priceInfo = $pricingManager->calculatePrice($storeId, $packageSize, $network);

if ($priceInfo['price'] !== null && $priceInfo['price'] > 0) {
    echo json_encode([
        'success' => true,
        'price' => $priceInfo['price'],
        'source' => $priceInfo['source'],
        'package_size' => $packageSize
    ]);
} else {
    echo json_encode([
        'success' => false,
        'message' => 'Price not available',
        'price' => null
    ]);
}
?>






