<?php

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

use App\Models\User;
use App\Models\Notification;
use Illuminate\Support\Facades\DB;

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

try {
    // Find the first active user
    $user = User::where('is_active', 1)->first();
    
    if (!$user) {
        echo "No active users found.\n";
        exit(1);
    }
    
    echo "Creating test notifications for user: {$user->name} (ID: {$user->id})\n";
    
    // Create test notifications with different priorities
    $notifications = [
        [
            'user_id' => $user->id,
            'type' => 'system_updates',
            'title' => 'Welcome to the new notification system!',
            'message' => 'You can now receive real-time notifications about your account activity.',
            'priority' => 'medium',
            'action_url' => '/dashboard',
            'is_read' => false,
        ],
        [
            'user_id' => $user->id,
            'type' => 'subscription_expiry',
            'title' => 'Subscription Expiring Soon',
            'message' => 'Your subscription will expire in 7 days. Please renew to continue access.',
            'priority' => 'high',
            'action_url' => '/payments/subscription',
            'is_read' => false,
        ],
        [
            'user_id' => $user->id,
            'type' => 'payment_failed',
            'title' => 'Payment Reminder',
            'message' => 'Your recent payment attempt needs attention. Please update your payment method.',
            'priority' => 'urgent',
            'action_url' => '/payments/update',
            'is_read' => false,
        ],
        [
            'user_id' => $user->id,
            'type' => 'account_approved',
            'title' => 'Profile Update',
            'message' => 'Your profile information has been successfully updated.',
            'priority' => 'low',
            'action_url' => '/profile',
            'is_read' => false,
        ],
    ];
    
    foreach ($notifications as $data) {
        $notification = Notification::create($data);
        echo "✓ Created: {$notification->title} (Priority: {$notification->priority})\n";
    }
    
    echo "\nSuccess! Created " . count($notifications) . " test notifications.\n";
    echo "User ID: {$user->id}\n";
    echo "Unread count: " . Notification::where('user_id', $user->id)->where('is_read', false)->count() . "\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo $e->getTraceAsString() . "\n";
    exit(1);
}
