<?php

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

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

$sub = DB::table('subscriptions')->where('id', 44)->first();

echo "Subscription Details:\n";
echo "ID: {$sub->id}\n";
echo "User ID: {$sub->user_id}\n";
echo "Stripe Customer: {$sub->stripe_customer_id}\n";
echo "Stripe Subscription: " . ($sub->stripe_subscription_id ?: 'EMPTY/NULL') . "\n";
echo "Current Period Start: {$sub->current_period_start}\n";
echo "Current Period End: {$sub->current_period_end}\n";
echo "Status: {$sub->status}\n";

if (empty($sub->stripe_subscription_id)) {
    echo "\n❌ PROBLEM: Stripe Subscription ID is empty!\n";
    echo "This is why webhooks aren't updating the database.\n";
    echo "The subscription wasn't created properly in Stripe.\n\n";
    
    echo "You need to:\n";
    echo "1. Cancel this subscription in the app\n";
    echo "2. Create a NEW subscription properly through the checkout flow\n";
    echo "3. Make sure it creates a Stripe subscription ID\n";
}
