<?php
require 'vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$pdo = new PDO(
    'mysql:host='.$_ENV['DB_HOST'].';dbname='.$_ENV['DB_DATABASE'],
    $_ENV['DB_USERNAME'],
    $_ENV['DB_PASSWORD']
);

echo "=== Fixing Subscription 38 Expires At ===\n\n";

// Get current subscription details
$stmt = $pdo->query('SELECT id, current_period_end, expires_at FROM subscriptions WHERE id = 38');
$sub = $stmt->fetch();

echo "Before:\n";
echo "  Current Period End: {$sub['current_period_end']}\n";
echo "  Expires At: {$sub['expires_at']}\n\n";

// Update expires_at to match current_period_end
$stmt = $pdo->prepare('UPDATE subscriptions SET expires_at = current_period_end WHERE id = 38');
$stmt->execute();

echo "Updating expires_at to match current_period_end...\n\n";

// Check the result
$stmt = $pdo->query('SELECT id, current_period_end, expires_at FROM subscriptions WHERE id = 38');
$sub = $stmt->fetch();

echo "After:\n";
echo "  Current Period End: {$sub['current_period_end']}\n";
echo "  Expires At: {$sub['expires_at']}\n\n";

echo "✓ Fixed! Subscription now expires on {$sub['expires_at']}\n";
