<?php

declare(strict_types=1);

namespace App\Support;

/**
 * 临时抑制 HasDberpAuditTrail 自动审计，用于业务语义日志或中间态 save 场景。
 */
final class DberpAuditTrailGuard
{
    private static int $depth = 0;

    /**
     * @template TReturn
     *
     * @param  callable(): TReturn  $callback
     * @return TReturn
     */
    public static function withoutAuditTrail(callable $callback): mixed
    {
        self::$depth++;

        try {
            return $callback();
        } finally {
            self::$depth--;
        }
    }

    public static function isEnabled(): bool
    {
        return self::$depth === 0;
    }
}
