import * as i0 from '@angular/core';
import { ModuleWithProviders, InjectionToken } from '@angular/core';
import { GrpcMessage, GrpcRequest, GrpcEvent } from '@ngx-grpc/common';
import { Observable } from 'rxjs';

declare class GrpcCoreModule {
    /**
     * Create GrpcCoreModule for using in AppModule (application root module)
     */
    static forRoot(): ModuleWithProviders<GrpcCoreModule>;
    /**
     * Create GrpcCoreModule for using in children modules (incl. lazy modules)
     */
    static forChild(): ModuleWithProviders<GrpcCoreModule>;
    static ɵfac: i0.ɵɵFactoryDeclaration<GrpcCoreModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<GrpcCoreModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<GrpcCoreModule>;
}

/**
 * Interceptor interface which should be implemented for custom interceptors
 */
interface GrpcInterceptor {
    /**
     * Interceptor entry point
     *
     * Example:
     *
     * ```
     *  intercept<Q extends GrpcMessage, S extends GrpcMessage>(request: GrpcRequest<Q, S>, next: GrpcHandler): Observable<GrpcEvent<S>> {
     *    // here do something before request, e.g. patch messages, metadata, etc
     *
     *    return next.handle(request).pipe(
     *      // here handle all messages, status codes, metadata, errors, retries etc
     *    );
     *  }
     * ```
     *
     * @param request intercepted request
     * @param next current GrpcHandler to pass the messages through
     */
    intercept<Q extends GrpcMessage, S extends GrpcMessage>(request: GrpcRequest<Q, S>, next: GrpcHandler): Observable<GrpcEvent<S>>;
}

/**
 * Core gRPC transport class. Implements creation and binding of RPCs to the clients.
 * There is a root GrpcHandler that handles all initial requests;
 * however for every interception a new instance of GrpcHandler is created and passed to the interceptor
 */
declare class GrpcHandler {
    private interceptors;
    constructor(configuredInterceptors: GrpcInterceptor | GrpcInterceptor[]);
    /**
     * Handles the gRPC request passing it through the interceptors array
     * Recursively calls all interceptors with a new instance of the GrpcHandler
     *
     * @param request a GrpcRequest to execute
     * @returns Observable of events returned by the GrpcClient implementation
     */
    handle<Q extends GrpcMessage, S extends GrpcMessage>(request: GrpcRequest<Q, S>): Observable<GrpcEvent<S>>;
    private message;
    private stream;
    static ɵfac: i0.ɵɵFactoryDeclaration<GrpcHandler, [{ optional: true; }]>;
    static ɵprov: i0.ɵɵInjectableDeclaration<GrpcHandler>;
}

/**
 * A configuration for GrpcLoggerInterceptor
 *
 * Example:
 *
 * ```
 * providers: [
 *   { provide: GRPC_LOGGER_SETTINGS, useValue: { enabled: true } },
 * ]
 * ```
 *
 * or more complex:
 *
 * ```
 * providers: [
 *   { provide: GRPC_LOGGER_SETTINGS, useFactory: () => { enabled: localStorage.getItem('GRPC_LOGGER_SETTINGS') === 'true' || !environment.prod } },
 * ]
 * ```
 */
declare const GRPC_LOGGER_SETTINGS: InjectionToken<unknown>;
/**
 * A configuration definition for GrpcLoggerInterceptor
 */
interface GrpcLoggerSettings {
    /**
     * Enables / disables the output, default true
     */
    enabled?: boolean;
    /**
     * Includes client settings into the logs, default true
     */
    logClientSettings?: boolean;
    /**
     * Includes request metadata into the logs, default true
     */
    logMetadata?: boolean;
    /**
     * Logs events with status code OK (0), default false
     */
    logStatusCodeOk?: boolean;
    /**
     * Request mapper function, defines what output is generated for the given message.
     * The default implementation is `(msg) => msg.toObject()`.
     * According to your preferences you might choose e.g. `(msg) => msg.toProtobufJSON()` instead.
     */
    requestMapper?: (msg: GrpcMessage) => any;
    /**
     * Response mapper function, defines what output is generated for the given message.
     * The default implementation is `(msg) => msg.toObject()`.
     * According to your preferences you might choose e.g. `(msg) => msg.toProtobufJSON()` instead.
     */
    responseMapper?: (msg: GrpcMessage) => any;
}
/**
 * Interceptor that implements logging of every request to the browser console
 *
 * Can be enabled / disabled by GRPC_LOGGER_ENABLED injection token
 */
declare class GrpcLoggerInterceptor implements GrpcInterceptor {
    private static requestId;
    private clientDataStyle;
    private dataStyle;
    private errorStyle;
    private statusOkStyle;
    private settings;
    constructor(settings?: GrpcLoggerSettings);
    intercept<Q extends GrpcMessage, S extends GrpcMessage>(request: GrpcRequest<Q, S>, next: GrpcHandler): Observable<GrpcEvent<S>>;
    static ɵfac: i0.ɵɵFactoryDeclaration<GrpcLoggerInterceptor, [{ optional: true; }]>;
    static ɵprov: i0.ɵɵInjectableDeclaration<GrpcLoggerInterceptor>;
}

interface GrpcLoggerRootOptions {
    settings: GrpcLoggerSettings;
}
interface GrpcLoggerChildOptions {
    settings: GrpcLoggerSettings;
}
declare class GrpcLoggerModule {
    /**
     * Create GrpcLoggerModule for using in AppModule (application root module)
     * You can provide the options here instead of injecting corresponding tokens separately
     */
    static forRoot(options?: GrpcLoggerRootOptions): ModuleWithProviders<GrpcLoggerModule>;
    /**
     * Create GrpcCoreModule for using in children modules (incl. lazy modules)
     * You can provide the options here instead of injecting corresponding tokens separately
     */
    static forChild(options?: GrpcLoggerChildOptions): ModuleWithProviders<GrpcLoggerModule>;
    static ɵfac: i0.ɵɵFactoryDeclaration<GrpcLoggerModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<GrpcLoggerModule, never, never, never>;
    static ɵinj: i0.ɵɵInjectorDeclaration<GrpcLoggerModule>;
}

/**
 * RxJS operator
 * When applied to gRPC events emits error for status events with a non-zero code (includes throwStatusErrors)
 *
 * @return Observable of gRPC events
 */
declare function throwStatusErrors<T extends GrpcMessage>(): (source$: Observable<GrpcEvent<T>>) => Observable<GrpcEvent<T>>;
/**
 * RxJS operator
 * When applied to gRPC events stream extracts and returns only messages
 *
 * @return Observable of messages
 */
declare function takeMessages<T extends GrpcMessage>(): (source$: Observable<GrpcEvent<T>>) => Observable<T>;

/**
 * Use this injection token to register the GrpcClientFactory
 *
 * Example:
 *
 * ```
 * providers: [
 *   { provide: GRPC_CLIENT_FACTORY, useClass: MyClientFactory },
 * ]
 * ```
 */
declare const GRPC_CLIENT_FACTORY: InjectionToken<unknown>;
/**
 * Use this injection token to add interceptors
 *
 * Example:
 *
 * ```
 * providers: [
 *   { provide: GRPC_INTERCEPTORS, useClass: MyInterceptor, multi: true },
 * ]
 * ```
 */
declare const GRPC_INTERCEPTORS: InjectionToken<unknown>;

export { GRPC_CLIENT_FACTORY, GRPC_INTERCEPTORS, GRPC_LOGGER_SETTINGS, GrpcCoreModule, GrpcHandler, GrpcLoggerInterceptor, GrpcLoggerModule, takeMessages, throwStatusErrors };
export type { GrpcInterceptor, GrpcLoggerChildOptions, GrpcLoggerRootOptions, GrpcLoggerSettings };
