<?php
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);

// Initialize Laravel
$app->make('db');

$token = \App\Models\Token::where('category_id', 1)->first();
$hod = \App\Models\User::where('designation', 'Head of Department')->first();

if ($token && $hod) {
    echo "Token: {$token->title}\n";
    echo "HOD: {$hod->name}\n";
    echo "HOD Department: {$hod->department->name} (ID: {$hod->department_id})\n";
    echo "HOD Designation: {$hod->designation}\n\n";
    
    echo "Token Approval Stages:\n";
    $stages = $token->category->categoryStages;
    foreach ($stages as $stage) {
        echo "  Stage {$stage->stage_order}: Dept {$stage->department_id} ({$stage->department->name}) / {$stage->designation}\n";
    }
    
    $policy = new \App\Policies\TokenPolicy(new \App\Services\ApprovalEngine());
    echo "\nAuthorization Check:\n";
    echo "Can view: " . ($policy->view($hod, $token) ? "YES\n" : "NO\n");
    echo "Can approve: " . ($policy->approve($hod, $token) ? "YES\n" : "NO\n");
}
?>
