<?php

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

use App\Models\ImmigoProSubscription;

$subId = $argv[1] ?? null;

if (!$subId) {
    echo "Usage: php force_next_charge.php <subscription_id>\n";
    exit(1);
}

$sub = ImmigoProSubscription::find($subId);

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

echo "\n========================================\n";
echo "BEFORE UPDATE\n";
echo "========================================\n";
echo "ID: " . $sub->id . "\n";
echo "Status: " . $sub->status . "\n";
echo "Paid: " . $sub->paid_installments . "/" . $sub->installments . "\n";
echo "Next Charge: " . ($sub->next_charge_date ? $sub->next_charge_date->format('Y-m-d H:i:s') : 'N/A') . "\n";
echo "========================================\n\n";

// Update next_charge_date to now so command will process it
$sub->update([
    'next_charge_date' => now()
]);

echo "✓ Updated next_charge_date to NOW\n";
echo "✓ Run this command to charge:\n";
echo "  php artisan immigopro:charge-installments\n\n";
