<?php

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

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

use App\Models\User;
use App\Models\Invoice;
use App\Models\Subscription;

echo "\n=== User Payment Data ===\n\n";

$user = User::find(1);

if (!$user) {
    echo "User not found\n";
    exit(1);
}

echo "User: {$user->name} (ID: {$user->id})\n\n";

// Check subscriptions
echo "--- Subscriptions ---\n";
$subscriptions = Subscription::where('user_id', $user->id)
    ->orderBy('created_at', 'desc')
    ->get();

if ($subscriptions->isEmpty()) {
    echo "No subscriptions found.\n";
} else {
    foreach ($subscriptions as $sub) {
        echo "ID: {$sub->id}\n";
        echo "  Package: {$sub->package_name}\n";
        echo "  Status: {$sub->status}\n";
        echo "  Amount: \${$sub->amount}\n";
        echo "  Activated: " . ($sub->activated_at ?? 'NULL') . "\n";
        echo "  Expires: " . ($sub->expires_at ?? 'NULL') . "\n";
        echo "  Created: {$sub->created_at}\n\n";
    }
}

// Check invoices
echo "--- Invoices ---\n";
$invoices = Invoice::where('user_id', $user->id)
    ->with('transactions')
    ->orderBy('created_at', 'desc')
    ->get();

if ($invoices->isEmpty()) {
    echo "No invoices found.\n";
} else {
    foreach ($invoices as $inv) {
        echo "ID: {$inv->id}\n";
        echo "  Invoice #: {$inv->invoice_number}\n";
        echo "  Amount: \${$inv->amount}\n";
        echo "  Status: {$inv->status}\n";
        echo "  Paid: " . ($inv->paid_at ?? 'NULL') . "\n";
        echo "  Transactions: " . $inv->transactions->count() . "\n";
        echo "  Created: {$inv->created_at}\n\n";
    }
}
