<?php
declare(strict_types=1);
require dirname(__DIR__) . '/app/bootstrap.php';
use App\Core\AccessControl;
use App\Core\Session;
$reflection=new ReflectionClass(AccessControl::class);$property=$reflection->getProperty('contextEnsured');$property->setAccessible(true);
$setUser=static function(array $roles,array $overrides=[],array $branches=[]) use($property):void{
 Session::put('user',['name'=>'POLICY_TEST','hospital'=>'njch','dashboard_role'=>1,'dashboard_role_fin'=>0,'dashboard_role_revenue'=>0,
 'access_control'=>['source'=>'ACL','roles'=>$roles,'overrides'=>$overrides,'branches'=>$branches]]);$property->setValue(null,true);
};
$setUser([['role_code'=>'SITE_ADMIN','policy_mode'=>'ALL','all_branches'=>1]]);
$checks=['admin_business'=>AccessControl::allows('revenue.view'),'admin_settings'=>AccessControl::allows('daily_revenue_settings.manage'),'admin_security'=>AccessControl::allows('security.access_control.manage')];
$setUser([['role_code'=>'GENERAL_MANAGER','policy_mode'=>'ALL_BUSINESS','all_branches'=>1]]);
$checks['gm_business']=AccessControl::allows('revenue.view');$checks['gm_export']=AccessControl::allows('daily_inpatient_revenue.export');$checks['gm_settings_excluded']=!AccessControl::allows('daily_revenue_settings.view');$checks['gm_security_excluded']=!AccessControl::allows('security.access_control.manage');
$setUser([['role_code'=>'GENERAL_MANAGER','policy_mode'=>'ALL_BUSINESS','all_branches'=>1]],['GENERAL_MANAGER'=>['daily_revenue_settings.view'=>'ALLOW','revenue.view'=>'DENY']]);
$checks['gm_override_allow_settings']=AccessControl::allows('daily_revenue_settings.view');$checks['gm_override_deny_business']=!AccessControl::allows('revenue.view');
$failed=[];foreach($checks as $k=>$ok){if(!$ok)$failed[]=$k;}echo json_encode(['schema'=>'R45_P14_POLICY_QA','checks'=>$checks,'passed'=>count($checks)-count($failed),'failed'=>$failed],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES),PHP_EOL;exit($failed===[]?0:1);
