<?php
namespace App\Middleware;

class OrgGuard
{
    public static function enforce()
    {
        if (!isset($_SESSION['user'])) {
            return;
        }

        // SuperAdmin bypass
        if (function_exists('is_superadmin') && is_superadmin()) {
            return;
        }

        if (!isset($_SESSION['user']['org_id'])) {
            http_response_code(403);
            echo "Organization context missing.";
            exit;
        }

        // Bind global org_id into session
        $_SESSION['org_id'] = $_SESSION['user']['org_id'];
    }
}
