<?php

namespace AIPT\Api\Chatbot\Jobs;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/**
 * Request-scoped idempotency key holder for chatbot provider calls.
 *
 * This context is intentionally backed by a private static property because it
 * must live only for the current PHP request / Action Scheduler execution. It
 * is never persisted and must be cleared after each worker run.
 */
class IdempotencyKeyContext {

    private static ?string $current_key = null;

    public static function setIdempotencyKey( string $key ): void {
        self::$current_key = trim( $key );
    }

    public static function getIdempotencyKey(): ?string {
        if ( null === self::$current_key ) {
            return null;
        }

        return '' === self::$current_key ? null : self::$current_key;
    }

    public static function clear(): void {
        self::$current_key = null;
    }
}
