<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Tools;

use App\Tools\Enums\ExecutionSource;
use Illuminate\Contracts\Auth\Authenticatable;

/**
 * 显式执行上下文。actor 必须由调用方传入且为真实 DBErp 用户，禁止从全局 Auth 推断。
 */
final readonly class ToolExecutionContext
{
    public function __construct(
        public Authenticatable $actor,
        public ExecutionSource $source,
        public string $correlationId = '',
        public ?string $clientId = null,
        public ?string $sessionId = null,
        public ?string $locale = null,
        public ?string $timezone = null,
        public ?string $currency = null,
        public ?string $requestId = null,
    ) {}

    public function withCorrelationId(string $correlationId): self
    {
        return new self(
            actor: $this->actor,
            source: $this->source,
            correlationId: $correlationId,
            clientId: $this->clientId,
            sessionId: $this->sessionId,
            locale: $this->locale,
            timezone: $this->timezone,
            currency: $this->currency,
            requestId: $this->requestId,
        );
    }
}
