<?php

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

use Illuminate\Support\Facades\Hash;
use App\Models\User;

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

echo "=== Testing Super Admin Login ===\n\n";

$email = 'admin@juris.local';
$password = 'password';

$user = User::where('email', $email)->first();

if (!$user) {
    echo "❌ User not found!\n";
    exit(1);
}

echo "✅ User found:\n";
echo "   ID: {$user->id}\n";
echo "   Name: {$user->name}\n";
echo "   Email: {$user->email}\n";
echo "   Email Verified: " . ($user->email_verified_at ? 'Yes' : 'No') . "\n";
echo "   Roles: " . $user->getRoleNames()->implode(', ') . "\n\n";

// Check password
if (Hash::check($password, $user->password)) {
    echo "✅ Password verification: SUCCESS\n\n";
} else {
    echo "❌ Password verification: FAILED\n";
    echo "   Resetting password to 'password'...\n";
    $user->password = Hash::make('password');
    $user->save();
    echo "   ✅ Password reset!\n\n";
}

// List permissions
echo "📋 Permissions:\n";
$permissions = $user->getAllPermissions();
if ($permissions->isEmpty()) {
    echo "   No specific permissions (super_admin has all access)\n";
} else {
    foreach ($permissions as $permission) {
        echo "   • {$permission->name}\n";
    }
}

echo "\n" . str_repeat("━", 50) . "\n";
echo "🎉 Super Admin is ready to use!\n";
echo str_repeat("━", 50) . "\n\n";

echo "📝 Login Credentials:\n";
echo "   URL: http://localhost:5173/login\n";
echo "   Email: admin@juris.local\n";
echo "   Password: password\n\n";
