<?php
require_once dirname(__DIR__) . '/config/config.php';

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

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

$countryId = intval($_GET['country_id'] ?? 0);
$serviceId = intval($_GET['service_id'] ?? 0);

if (!$countryId || !$serviceId) {
    echo json_encode(['error' => 'Country and service required']);
    exit;
}

$pdo = getDBConnection();

// Get price from database
$stmt = $pdo->prepare("SELECT * FROM sms_pricing WHERE country_id = ? AND service_id = ? AND status = 'active'");
$stmt->execute([$countryId, $serviceId]);
$pricing = $stmt->fetch();

if ($pricing) {
    echo json_encode([
        'success' => true,
        'api_price' => $pricing['api_price'],
        'custom_price' => $pricing['custom_price']
    ]);
} else {
    echo json_encode(['error' => 'Price not available']);
}