/** @packageDocumentation
 * @module RpcInterface
 */
import { BeEvent } from "@itwin/core-bentley";
import { IModelRpcProps } from "../../IModel";
import { RpcInterface, RpcInterfaceDefinition } from "../../RpcInterface";
import { RpcConfiguration } from "./RpcConfiguration";
import { RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl } from "./RpcConstants";
import { RpcNotFoundResponse } from "./RpcControl";
import { RpcInvocation, SerializedRpcActivity } from "./RpcInvocation";
import { RpcSerializedValue } from "./RpcMarshaling";
import { RpcOperation } from "./RpcOperation";
import { RpcRequest } from "./RpcRequest";
/** A serialized RPC operation descriptor.
 * @internal
 */
export interface SerializedRpcOperation {
    interfaceDefinition: string;
    operationName: string;
    interfaceVersion: string;
    encodedRequest?: string;
}
/** A serialized RPC operation request.
 * @internal
 */
export interface SerializedRpcRequest extends SerializedRpcActivity {
    operation: SerializedRpcOperation;
    method: string;
    path: string;
    parameters: RpcSerializedValue;
    caching: RpcResponseCacheControl;
    ip?: string;
    protocolVersion?: number;
    parametersOverride?: any[];
}
/** An RPC operation request fulfillment.
 * @internal
 */
export interface RpcRequestFulfillment {
    /** The RPC interface for the request. */
    interfaceName: string;
    /** The id for the request. */
    id: string;
    /** The result for the request. */
    result: RpcSerializedValue;
    /** The un-serialized result for the request. */
    rawResult: any;
    /** A protocol-specific status code value for the request. */
    status: number;
    retry?: string;
    /** Whether to compress the result with one of the client's supported encodings. Defaults to true. */
    allowCompression?: boolean;
}
/** @internal */
export declare namespace RpcRequestFulfillment {
    function forUnknownError(request: SerializedRpcRequest, error: any): Promise<RpcRequestFulfillment>;
}
/** Handles RPC protocol events.
 * @internal
 */
export type RpcProtocolEventHandler = (type: RpcProtocolEvent, object: RpcRequest | RpcInvocation, err?: any) => void;
/** Documents changes to the RPC protocol version.
 * @internal
 */
export declare enum RpcProtocolVersion {
    None = 0,
    IntroducedNoContent = 1,
    IntroducedStatusCategory = 2
}
/**
 * A backend response that is handled internally by the RPC system.
 * @internal
 */
export interface RpcManagedStatus {
    iTwinRpcCoreResponse: true;
    managedStatus: "pending" | "notFound" | "noContent";
    responseValue: string | {
        message: string;
    } | RpcNotFoundResponse;
}
/** An application protocol for an RPC interface.
 * @internal
 */
export declare abstract class RpcProtocol {
    /** Events raised by all protocols. See [[RpcProtocolEvent]] */
    static readonly events: BeEvent<RpcProtocolEventHandler>;
    /** A version code that identifies the RPC protocol capabilties of this endpoint. */
    static readonly protocolVersion: number;
    /** The name of the RPC protocol version header. */
    protocolVersionHeaderName: string;
    /** Events raised by the protocol. See [[RpcProtocolEvent]] */
    readonly events: BeEvent<RpcProtocolEventHandler>;
    /** The configuration for the protocol. */
    readonly configuration: RpcConfiguration;
    /** The RPC request class for this protocol. */
    abstract readonly requestType: typeof RpcRequest;
    /** The RPC invocation class for this protocol. */
    readonly invocationType: typeof RpcInvocation;
    serializedClientRequestContextHeaderNames: SerializedRpcActivity;
    /** If greater than zero, specifies where to break large binary request payloads. */
    transferChunkThreshold: number;
    /** Used by protocols that can transmit stream values natively. */
    preserveStreams: boolean;
    /** Used by protocols that can transmit IModelRpcProps values natively. */
    checkToken: boolean;
    /** Used by protocols that support user-defined status codes. */
    supportsStatusCategory: boolean;
    /** If checkToken is true, will be called on the backend to inflate the IModelRpcProps for each request. */
    inflateToken(tokenFromBody: IModelRpcProps, _request: SerializedRpcRequest): IModelRpcProps;
    /** Override to supply the status corresponding to a protocol-specific code value. */
    getStatus(code: number): RpcRequestStatus;
    /** Override to supply the protocol-specific code corresponding to a status value. */
    getCode(status: RpcRequestStatus): number;
    /** Override to supply the protocol-specific path value for an RPC operation. */
    supplyPathForOperation(operation: RpcOperation, _request: RpcRequest | undefined): string;
    /** Override to supply the operation for a protocol-specific path value. */
    getOperationFromPath(path: string): SerializedRpcOperation;
    /** Obtains the implementation result on the backend for an RPC operation request. */
    fulfill(request: SerializedRpcRequest): Promise<RpcRequestFulfillment>;
    /** Serializes a request. */
    serialize(request: RpcRequest): Promise<SerializedRpcRequest>;
    /** Constructs a protocol. */
    constructor(configuration: RpcConfiguration);
    /** @internal */
    onRpcClientInitialized(_definition: RpcInterfaceDefinition, _client: RpcInterface): void;
    /** @internal */
    onRpcImplInitialized(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void;
    /** @internal */
    onRpcClientTerminated(_definition: RpcInterfaceDefinition, _client: RpcInterface): void;
    /** @internal */
    onRpcImplTerminated(_definition: RpcInterfaceDefinition, _impl: RpcInterface): void;
}
//# sourceMappingURL=RpcProtocol.d.ts.map