/**
 * The cluster `Message` module defines the in-memory shapes used while moving
 * requests and control envelopes between callers, durable storage, transports,
 * and entity runners.
 *
 * **Common use cases**
 *
 * - Representing outgoing entity requests before they are stored or sent
 * - Reconstructing incoming requests that runners read from storage or transport
 * - Converting outgoing messages into local, in-process deliveries
 * - Serializing request payloads with the associated RPC schema and context
 * - Passing control envelopes such as acknowledgements and interrupts through
 *   without payload decoding
 *
 * **Gotchas**
 *
 * - Requests can exist in decoded local form or encoded persisted form; choose
 *   `IncomingLocal` / `OutgoingRequest` for local delivery and `IncomingRequest`
 *   / `Envelope.PartialRequest` for storage or transport boundaries.
 * - Request payloads must be encoded and decoded with the matching RPC payload
 *   schema and service context, otherwise failures are surfaced as
 *   `MalformedMessage`.
 * - Delivery state such as the last sent or received reply is carried alongside
 *   messages so retries and persisted replies can preserve cluster semantics.
 *
 * @since 4.0.0
 */
import * as Context from "../../Context.ts";
import * as Effect from "../../Effect.ts";
import * as Option from "../../Option.ts";
import * as Rpc from "../rpc/Rpc.ts";
import type { PersistenceError } from "./ClusterError.ts";
import { MalformedMessage } from "./ClusterError.ts";
import type { EntityAddress } from "./EntityAddress.ts";
import * as Envelope from "./Envelope.ts";
import type * as Reply from "./Reply.ts";
import type { Snowflake } from "./Snowflake.ts";
/**
 * Message read by a runner from storage or transport.
 *
 * **Details**
 *
 * An incoming message is either a persisted request with an encoded payload or an
 * incoming control envelope.
 *
 * @category incoming
 * @since 4.0.0
 */
export type Incoming<R extends Rpc.Any> = IncomingRequest<R> | IncomingEnvelope;
/**
 * Locally decoded incoming message for in-process delivery.
 *
 * **Details**
 *
 * It is either a request with a decoded payload or an incoming control envelope.
 *
 * @category incoming
 * @since 4.0.0
 */
export type IncomingLocal<R extends Rpc.Any> = IncomingRequestLocal<R> | IncomingEnvelope;
/**
 * Converts an outgoing message into a locally deliverable incoming message.
 *
 * **Details**
 *
 * Request messages keep their decoded payload and response callback, while
 * control envelopes are wrapped as incoming envelopes.
 *
 * @category incoming
 * @since 4.0.0
 */
export declare const incomingLocalFromOutgoing: <R extends Rpc.Any>(self: Outgoing<R>) => IncomingLocal<R>;
declare const IncomingRequest_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
    readonly _tag: "IncomingRequest";
} & import("../../Pipeable.ts").Pipeable;
/**
 * Represents an incoming persisted request whose payload has not yet been decoded with the RPC
 * schema.
 *
 * **Details**
 *
 * It carries the last reply that was sent and a callback for persisting encoded
 * replies.
 *
 * @category incoming
 * @since 4.0.0
 */
export declare class IncomingRequest<R extends Rpc.Any> extends IncomingRequest_base<{
    readonly envelope: Envelope.PartialRequest;
    readonly lastSentReply: Option.Option<Reply.Encoded>;
    readonly respond: (reply: Reply.ReplyWithContext<R>) => Effect.Effect<void, MalformedMessage | PersistenceError>;
}> {
}
declare const IncomingRequestLocal_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
    readonly _tag: "IncomingRequestLocal";
} & import("../../Pipeable.ts").Pipeable;
/**
 * Represents an incoming request for local delivery with a decoded payload.
 *
 * **Details**
 *
 * It includes dynamic annotations, the last sent reply, and a callback for
 * replying with decoded replies.
 *
 * @category incoming
 * @since 4.0.0
 */
export declare class IncomingRequestLocal<R extends Rpc.Any> extends IncomingRequestLocal_base<{
    readonly envelope: Envelope.Request<R>;
    readonly lastSentReply: Option.Option<Reply.Reply<R>>;
    readonly respond: (reply: Reply.Reply<R>) => Effect.Effect<void, MalformedMessage | PersistenceError>;
    readonly annotations: Context.Context<never>;
}> {
}
declare const IncomingEnvelope_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
    readonly _tag: "IncomingEnvelope";
} & import("../../Pipeable.ts").Pipeable;
/**
 * Represents an incoming control envelope carrying an `AckChunk` or `Interrupt`.
 *
 * @category incoming
 * @since 4.0.0
 */
export declare class IncomingEnvelope extends IncomingEnvelope_base<{
    readonly _tag: "IncomingEnvelope";
    readonly envelope: Envelope.AckChunk | Envelope.Interrupt;
}> {
}
/**
 * Message produced for storage or transport.
 *
 * **Details**
 *
 * An outgoing message is either an entity request or a control envelope.
 *
 * @category outgoing
 * @since 4.0.0
 */
export type Outgoing<R extends Rpc.Any> = OutgoingRequest<R> | OutgoingEnvelope;
declare const OutgoingRequest_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
    readonly _tag: "OutgoingRequest";
} & import("../../Pipeable.ts").Pipeable;
/**
 * Represents an outgoing entity request with decoded payload and RPC metadata.
 *
 * **Details**
 *
 * It carries the service context used for serialization, the last received reply,
 * the reply callback, dynamic annotations, and an optional encoded request cache.
 *
 * @category outgoing
 * @since 4.0.0
 */
export declare class OutgoingRequest<R extends Rpc.Any> extends OutgoingRequest_base<{
    readonly envelope: Envelope.Request<R>;
    readonly context: Context.Context<Rpc.Services<R>>;
    readonly lastReceivedReply: Option.Option<Reply.Reply<R>>;
    readonly rpc: R;
    readonly respond: (reply: Reply.Reply<R>) => Effect.Effect<void>;
    readonly annotations: Context.Context<never>;
}> {
    /**
     * Cached encoded envelope payload reused when sending the request.
     *
     * @since 4.0.0
     */
    encodedCache?: Envelope.PartialRequest;
}
declare const OutgoingEnvelope_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
    readonly _tag: "OutgoingEnvelope";
} & import("../../Pipeable.ts").Pipeable;
/**
 * Represents an outgoing control envelope paired with RPC metadata.
 *
 * **When to use**
 *
 * Use to construct an interrupt envelope for an
 * in-flight request.
 *
 * @category outgoing
 * @since 4.0.0
 */
export declare class OutgoingEnvelope extends OutgoingEnvelope_base<{
    readonly envelope: Envelope.AckChunk | Envelope.Interrupt;
    readonly rpc: Rpc.AnyWithProps;
}> {
    /**
     * Creates an outgoing interrupt envelope for the supplied request.
     *
     * @since 4.0.0
     */
    static interrupt(options: {
        readonly address: EntityAddress;
        readonly id: Snowflake;
        readonly requestId: Snowflake;
    }): OutgoingEnvelope;
}
/**
 * Serializes an outgoing message into a partial envelope.
 *
 * **Details**
 *
 * Control envelopes pass through unchanged. Requests are encoded with their RPC
 * payload schema, reusing the cached encoded request when available.
 *
 * @category serialization
 * @since 4.0.0
 */
export declare const serialize: <Rpc extends Rpc.Any>(message: Outgoing<Rpc>) => Effect.Effect<Envelope.Partial, MalformedMessage>;
/**
 * Serializes an outgoing message into its JSON envelope representation.
 *
 * **Details**
 *
 * Schema encoding failures are converted to `MalformedMessage`.
 *
 * @category serialization
 * @since 4.0.0
 */
export declare const serializeEnvelope: <Rpc extends Rpc.Any>(message: Outgoing<Rpc>) => Effect.Effect<Envelope.Encoded, MalformedMessage, never>;
/**
 * Encodes the payload of an `OutgoingRequest` with the request's RPC payload
 * schema and service context.
 *
 * **Details**
 *
 * The result is a `PartialRequest` suitable for storage or transport.
 *
 * @category serialization
 * @since 4.0.0
 */
export declare const serializeRequest: <Rpc extends Rpc.Any>(self: OutgoingRequest<Rpc>) => Effect.Effect<Envelope.PartialRequest, MalformedMessage>;
/**
 * Decodes a partial envelope back into a locally deliverable incoming message.
 *
 * **Details**
 *
 * Control envelopes pass through directly. Request envelopes require the original
 * `OutgoingRequest` so the payload can be decoded with the correct RPC schema and
 * context.
 *
 * @category serialization
 * @since 4.0.0
 */
export declare const deserializeLocal: <Rpc extends Rpc.Any>(self: Outgoing<Rpc>, encoded: Envelope.Partial) => Effect.Effect<IncomingLocal<Rpc>, MalformedMessage>;
export {};
//# sourceMappingURL=Message.d.ts.map