<?php
namespace App\Services;
use App\Models\{Project,User,Ticket};
class Access {
 public static function project(User $u,Project $p):void {abort_unless($u->active&&Project::visibleTo($u)->whereKey($p->id)->exists(),403,'اجازه دسترسی به این پروژه را ندارید.');}
 public static function manage(User $u,?Project $p=null):void {abort_unless($u->active&&$u->isManager(),403);if($p)self::project($u,$p);}
 public static function ticket(User $u,Ticket $t):void {if($t->project){self::project($u,$t->project);}else abort_unless($t->user_id===$u->id||$u->role==='admin',403);}
 public static function audit($action,$reference,$data=[]):void {\App\Models\AuditLog::create(['user_id'=>auth()->id(),'action'=>$action,'reference'=>(string)$reference,'data'=>$data]);}
}
