<?php

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

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

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

echo "=== Checking Marketing Officer Roles ===\n\n";

$email = 'anuradhasampath999@gmail.com';
$user = User::where('email', $email)->first();

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

echo "User: {$user->name} (ID: {$user->id})\n";
echo "Email: {$user->email}\n";
echo "Super Admin: " . ($user->is_super_admin ? 'Yes' : 'No') . "\n\n";

echo "Roles from model_has_roles table:\n";
$roles = DB::table('model_has_roles')
    ->join('roles', 'model_has_roles.role_id', '=', 'roles.id')
    ->where('model_has_roles.model_type', 'App\\Models\\User')
    ->where('model_has_roles.model_id', $user->id)
    ->get(['roles.name', 'roles.id']);

if ($roles->isEmpty()) {
    echo "  ⚠️  NO ROLES ASSIGNED!\n\n";
} else {
    foreach ($roles as $role) {
        echo "  - {$role->name} (ID: {$role->id})\n";
    }
    echo "\n";
}

echo "Using hasRole() method:\n";
echo "  hasRole('marketing_officer'): " . ($user->hasRole('marketing_officer') ? 'YES' : 'NO') . "\n";
echo "  hasRole('super_admin'): " . ($user->hasRole('super_admin') ? 'YES' : 'NO') . "\n\n";

echo "All available roles:\n";
$allRoles = DB::table('roles')->get(['id', 'name']);
foreach ($allRoles as $role) {
    echo "  - {$role->name} (ID: {$role->id})\n";
}
