<?php

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

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

use App\Models\SubscriptionPackage;

echo "=== Subscription Packages ===" . PHP_EOL . PHP_EOL;

$packages = SubscriptionPackage::all();

if ($packages->isEmpty()) {
    echo "No packages found. Creating sample packages..." . PHP_EOL . PHP_EOL;
    
    $samplePackages = [
        [
            'name_en' => 'Basic',
            'name_fr' => 'Basique',
            'description_en' => 'Perfect for individuals and small teams getting started',
            'description_fr' => 'Parfait pour les particuliers et les petites équipes qui démarrent',
            'features_en' => [
                'Up to 10 transactions/month',
                'Basic reporting',
                'Email support',
                'Access to client portal'
            ],
            'features_fr' => [
                'Jusqu\'à 10 transactions/mois',
                'Rapports de base',
                'Support par email',
                'Accès au portail client'
            ],
            'monthly_price' => 19.00,
            'yearly_price' => 190.00,
            'is_active' => true,
            'portal_access' => ['payments']
        ],
        [
            'name_en' => 'Professional',
            'name_fr' => 'Professionnel',
            'description_en' => 'Advanced features for growing businesses',
            'description_fr' => 'Fonctionnalités avancées pour les entreprises en croissance',
            'features_en' => [
                'Unlimited transactions',
                'Advanced reporting & analytics',
                'Priority support',
                'Custom payment gateway',
                'API access'
            ],
            'features_fr' => [
                'Transactions illimitées',
                'Rapports et analyses avancés',
                'Support prioritaire',
                'Passerelle de paiement personnalisée',
                'Accès API'
            ],
            'monthly_price' => 49.00,
            'yearly_price' => 490.00,
            'is_active' => true,
            'portal_access' => ['payments', 'lms']
        ],
        [
            'name_en' => 'Enterprise',
            'name_fr' => 'Entreprise',
            'description_en' => 'Full-scale solution for large organizations',
            'description_fr' => 'Solution complète pour les grandes organisations',
            'features_en' => [
                'Everything in Professional',
                'White-label solution',
                'Dedicated account manager',
                '24/7 premium support',
                'Custom integrations',
                'SLA guarantee'
            ],
            'features_fr' => [
                'Tout ce qui est dans Professionnel',
                'Solution en marque blanche',
                'Gestionnaire de compte dédié',
                'Support premium 24/7',
                'Intégrations personnalisées',
                'Garantie SLA'
            ],
            'monthly_price' => 99.00,
            'yearly_price' => 990.00,
            'is_active' => true,
            'portal_access' => ['payments', 'lms', 'cms']
        ],
    ];
    
    foreach ($samplePackages as $packageData) {
        $package = SubscriptionPackage::create($packageData);
        echo "✓ Created: {$package->name_en} (\${$package->monthly_price}/month)" . PHP_EOL;
    }
    
    echo PHP_EOL . "Sample packages created successfully!" . PHP_EOL;
} else {
    echo "Found {$packages->count()} package(s):" . PHP_EOL . PHP_EOL;
    
    foreach ($packages as $package) {
        echo "ID: {$package->id}" . PHP_EOL;
        echo "Name: {$package->name_en}" . PHP_EOL;
        echo "Price: \${$package->monthly_price}/month" . PHP_EOL;
        echo "Status: " . ($package->is_active ? 'Active' : 'Inactive') . PHP_EOL;
        echo "Features: " . count($package->features_en ?? []) . PHP_EOL;
        echo PHP_EOL;
    }
}
