/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Message } from "#codec/MessageCodec.js";
import { AsyncObservableValue, Bytes, Duration, Lifetime } from "#general";
import { Session } from "#session/Session.js";
import { SessionParameters } from "#session/SessionParameters.js";
import { NodeId } from "#types";
import { MessageChannel } from "./MessageChannel.js";
export type ExchangeLogContext = Record<string, unknown>;
export type ExchangeSendOptions = {
    /**
     * The response to this send should be an ack only and no StatusResponse or such. If a StatusResponse is returned
     * then this is handled as error.
     */
    expectAckOnly?: boolean;
    /**
     * If the message is part of a multiple message interaction, this flag indicates that it is not allowed
     * to establish a new exchange
     */
    multipleMessageInteraction?: boolean;
    /**
     * Defined an expected processing time by the responder for the message. This is used to calculate the final
     * timeout for responses together with the normal retransmission logic when MRP is used.
     */
    expectedProcessingTime?: Duration;
    /** Allows to specify if the send message requires to be acknowledged by the receiver or not. */
    requiresAck?: boolean;
    /** Use the provided acknowledge MessageId instead checking the latest to send one */
    includeAcknowledgeMessageId?: number;
    /**
     * Disables the MRP logic which means that no retransmissions are done and receiving an ack is not awaited.
     */
    disableMrpLogic?: boolean;
    /** Additional context information for logging to be included at the beginning of the Message log. */
    logContext?: ExchangeLogContext;
    /** Allows to override the protocol ID of the message, mainly used for standalone acks. */
    protocolId?: number;
};
/**
 * Message size overhead of a Matter message:
 * 26 (Matter Message Header) + 12 (Matter Payload Header) taken from https://github.com/project-chip/connectedhomeip/blob/2d97cda23024e72f36216900ca667bf1a0d9499f/src/system/SystemConfig.h#L327
 * 16 byte MIC is then also needed to be excluded from the max payload size
 * Secure Extensions and Message Extensions need to be handled by exchange additionally!
 */
export declare const MATTER_MESSAGE_OVERHEAD: number;
/**
 * Interfaces {@link MessageExchange} with other components.
 */
export interface MessageExchangeContext {
    session: Session;
    retry(number: number): void;
    localSessionParameters: SessionParameters;
}
/**
 * A Matter "message exchange" is a sequence of messages associated with a single interaction.
 *
 * TODO - rewrite using sleeps and abort controller
 */
export declare class MessageExchange {
    #private;
    static fromInitialMessage(context: MessageExchangeContext, initialMessage: Message): MessageExchange;
    static initiate(context: MessageExchangeContext, exchangeId: number, protocolId: number): MessageExchange;
    constructor(config: MessageExchange.Config);
    get context(): MessageExchangeContext;
    get isInitiator(): boolean;
    /** Emits when the exchange is actually closed. This happens after all Retries and Communication are done. */
    get closed(): AsyncObservableValue<[any, ...any[]]>;
    get considerClosed(): any;
    /**
     * Emit when the exchange is closing, but not yet closed. We only wait for acks and retries to happen, but the
     * actual interaction logic is already done.
     */
    get closing(): AsyncObservableValue<[any, ...any[]]>;
    get id(): number;
    get idStr(): string;
    get session(): Session;
    get channel(): MessageChannel;
    /**
     * Max Payload size of the exchange which bases on the maximum payload size of the channel reduced by Matter
     * protocol overhead.
     */
    get maxPayloadSize(): number;
    join(...name: unknown[]): Lifetime;
    onMessageReceived(message: Message, duplicate?: boolean): Promise<void>;
    send(messageType: number, payload: Bytes, options?: ExchangeSendOptions): Promise<void>;
    nextMessage(options?: {
        expectedProcessingTime?: Duration;
        timeout?: Duration;
    }): Promise<Message>;
    [Symbol.asyncDispose](): Promise<void>;
    destroy(): Promise<void>;
    startTimedInteraction(timeout: Duration): void;
    clearTimedInteraction(): void;
    hasTimedInteraction(): boolean;
    hasActiveTimedInteraction(): boolean;
    hasExpiredTimedInteraction(): boolean;
    /**
     * Closes the exchange.
     * If force is true, the exchange will be closed immediately, even if there are still messages to send.
     * If force is false, the exchange will be closed only after all messages have been sent.
     */
    close(force?: boolean): Promise<void>;
    get via(): string;
    /**
     * Expose some diagnostics for logging.
     * For simply one message exchanges without retransmissions nothing will be exposed
     */
    get diagnostics(): string;
}
export declare namespace MessageExchange {
    interface Config {
        context: MessageExchangeContext;
        isInitiator: boolean;
        peerSessionId: number;
        nodeId?: NodeId;
        peerNodeId?: NodeId;
        exchangeId: number;
        protocolId: number;
    }
}
//# sourceMappingURL=MessageExchange.d.ts.map