<?php

declare(strict_types=1);

namespace App\Support;

use Illuminate\Support\Str;

/**
 * 单次 HTTP 请求内的审计关联 ID，用于将同一操作触发的多条日志归组。
 */
final class DberpAuditCorrelationContext
{
    private static ?string $id = null;

    public static function ensure(): string
    {
        if (self::$id === null || self::$id === '') {
            self::$id = (string) Str::uuid();
        }

        return self::$id;
    }

    public static function id(): ?string
    {
        return self::$id;
    }

    public static function reset(?string $id = null): void
    {
        self::$id = $id;
    }
}
