#!/bin/bash

# SSH into production and run these commands
# Replace with your actual server details

echo "=== STEP 1: Check if AuditPolicy.php has correct code ==="
echo "SSH to your server and run:"
echo "grep -n 'use App\\\\Models\\\\User' /home3/mvslabco/yellow.mvslab.com/app/Policies/AuditPolicy.php"
echo ""

echo "=== STEP 2: Verify auditor has Create:Audit permission in database ==="
echo "SSH and run:"
echo "cd /home3/mvslabco/yellow.mvslab.com && php artisan tinker"
echo "Then paste this:"
echo ""
echo "\$auditor_role = Spatie\Permission\Models\Role::where('name', 'auditor')->first();"
echo "if (\$auditor_role) {"
echo "  \$perms = \$auditor_role->permissions->pluck('name');"
echo "  echo 'Auditor has Create:Audit: ' . (\$perms->contains('Create:Audit') ? 'YES' : 'NO') . PHP_EOL;"
echo "  \$perms->dump();"
echo "}"
echo ""

echo "=== STEP 3: Check server error logs ==="
echo "SSH and check:"
echo "tail -f /home3/mvslabco/yellow.mvslab.com/storage/logs/laravel.log"
echo ""

echo "=== STEP 4: Verify user is authenticated and has role ==="
echo "In tinker:"
echo "\$user = App\Models\User::find(YOUR_AUDITOR_USER_ID);"
echo "echo 'Has auditor role: ' . (\$user->hasRole('auditor') ? 'YES' : 'NO') . PHP_EOL;"
echo "echo 'Can Create:Audit: ' . (\$user->can('Create:Audit') ? 'YES' : 'NO') . PHP_EOL;"
echo "\$user->load('roles', 'permissions');"
echo "\$user->dump();"
