<?php

require __DIR__ . '/vendor/autoload.php';

use App\Models\ImmigoProPackage;

// Bootstrap Laravel
$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

echo "=== Checking Package ID 1 Payment Plans ===\n\n";

$pkg = ImmigoProPackage::find(1);

if (!$pkg) {
    echo "❌ Package ID 1 not found!\n";
    exit;
}

echo "Package: {$pkg->name_en}\n";
echo "Base Price: \${$pkg->base_price}\n\n";

echo "Payment Plans Data:\n";
echo json_encode($pkg->payment_plans, JSON_PRETTY_PRINT) . "\n\n";

if ($pkg->payment_plans) {
    echo "✅ Payment plans exist:\n";
    echo "  Full Payment Discount: " . ($pkg->payment_plans['full_payment_discount'] ?? 'NOT SET') . "%\n";
    echo "  3-Month Upfront: " . ($pkg->payment_plans['three_month_upfront'] ?? 'NOT SET') . "%\n";
    echo "  6-Month Upfront: " . ($pkg->payment_plans['six_month_upfront'] ?? 'NOT SET') . "%\n";
    echo "  12-Month Upfront: " . ($pkg->payment_plans['twelve_month_upfront'] ?? 'NOT SET') . "%\n";
} else {
    echo "❌ No payment plans data!\n";
}

echo "\n=== Testing Public API Endpoint ===\n\n";
// Simulate what the frontend receives
$response = \Illuminate\Support\Facades\Http::get('http://localhost:8000/api/v1/immigopro-packages/public');
$data = $response->json();

if (isset($data['data']) && count($data['data']) > 0) {
    $package = $data['data'][0];
    echo "✅ Public API Response:\n";
    echo "Package Name: " . $package['name_en'] . "\n";
    echo "Payment Plans: " . json_encode($package['payment_plans'] ?? 'NULL') . "\n";
} else {
    echo "❌ No data from public API\n";
}
