import { ClientConfig } from "./modules";
export declare type ResponseHandler = (params: any, responseType: number) => void;
declare type TypedParams = Record<string, unknown>;
declare type ResultOrError = {
    result: any;
} | {
    error: {
        message: string;
        code: number;
        data?: any;
    };
};
export interface BinaryLibraryBase {
    getLibName(): Promise<string>;
    createContext(configJson: string): Promise<string>;
    destroyContext(context: number): void;
}
export interface BinaryLibrary extends BinaryLibraryBase {
    setResponseHandler(handler?: (requestId: number, paramsJson: string, responseType: ResponseType, finished: boolean) => void): void;
    sendRequest(context: number, requestId: number, functionName: string, functionParamsJson: string): void;
}
export interface BinaryLibraryWithParams extends BinaryLibraryBase {
    setResponseParamsHandler(handler?: (requestId: number, params: TypedParams, responseType: ResponseType, finished: boolean) => void): void;
    sendRequestParams(context: number, requestId: number, functionName: string, functionParams: TypedParams): void;
}
export interface SyncBinaryLibraryBase {
    getLibName(): string;
    createContext(configJson: string): string;
    destroyContext(context: number): void;
}
export interface SyncBinaryLibrary extends SyncBinaryLibraryBase {
    setResponseHandler(handler?: (requestId: number, paramsJson: string, responseType: ResponseType, finished: boolean) => void): void;
    sendRequest(context: number, requestId: number, functionName: string, functionParamsJson: string): void;
    requestSync(context: number, functionName: string, functionParamsJson: string): string;
}
export interface SyncBinaryLibraryWithParams extends SyncBinaryLibraryBase {
    setResponseParamsHandler(handler?: (requestId: number, params: TypedParams, responseType: ResponseType, finished: boolean) => void): void;
    sendRequestParams(context: number, requestId: number, functionName: string, functionParams: TypedParams): void;
    requestParamsSync(context: number, functionName: string, functionParams?: TypedParams): ResultOrError | undefined;
}
export declare enum ResponseType {
    Success = 0,
    Error = 1,
    Nop = 2,
    AppRequest = 3,
    AppNotify = 4,
    Custom = 100
}
export declare function getBridge(): BinaryBridge;
declare type IBinaryLibrary = BinaryLibrary | BinaryLibraryWithParams | SyncBinaryLibrary | SyncBinaryLibraryWithParams;
declare type BinaryLoader = () => Promise<IBinaryLibrary> | IBinaryLibrary;
export declare function useLibrary(loader: BinaryLoader): void;
export declare class BinaryBridge {
    private loading;
    private loadError;
    private binding;
    private requests;
    private nextRequestId;
    private contextCount;
    private responseHandlerAssigned;
    constructor(loader: BinaryLoader);
    private checkResponseHandler;
    getLibName(): Promise<string>;
    getLibNameSync(): string;
    createContext(config: ClientConfig): Promise<number>;
    createContextSync(config: ClientConfig): number;
    destroyContext(context: number): void;
    request<P, R>(context: number, functionName: string, functionParams: P, responseHandler?: ResponseHandler): Promise<R>;
    requestSync<P, R>(context: number, functionName: string, functionParams: P): R;
    private bindingRequired;
    private syncLibraryRequired;
    private generateRequestId;
    private handleLibraryResponse;
    private static parseResult;
    private static parseResultParams;
}
export {};
//# sourceMappingURL=bin.d.ts.map