<?php

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

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

echo "Testing ImmigoPro Admin API Endpoint\n";
echo "====================================\n\n";

// Test the controller method directly
$controller = new \App\Http\Controllers\Api\V1\ImmigoProSubscriptionController();

try {
    $response = $controller->getAllSubscriptions();
    $content = $response->getContent();
    $data = json_decode($content, true);
    
    echo "API Response:\n";
    echo json_encode($data, JSON_PRETTY_PRINT) . "\n\n";
    
    if (isset($data['data']) && !empty($data['data'])) {
        echo "✓ Found " . count($data['data']) . " ImmigoPro subscription(s)\n";
        foreach ($data['data'] as $sub) {
            echo "\nSubscription ID: " . $sub['id'] . "\n";
            echo "  User: " . ($sub['user']['email'] ?? 'N/A') . "\n";
            echo "  Package: " . $sub['package_name'] . "\n";
            echo "  Status: " . $sub['status'] . "\n";
            echo "  Total: $" . $sub['total_amount'] . "\n";
            echo "  Installments: " . $sub['paid_installments'] . "/" . $sub['installments'] . "\n";
        }
    } else {
        echo "✗ No subscriptions found\n";
    }
} catch (\Exception $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
    echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}
