/*!
 * Paradigm Framework - Angular Wrapper
 * Copyright (c) 2017 Miracle Devs, Inc
 * Licensed under MIT (https://github.com/MiracleDevs/Paradigm.Web.Angular/blob/master/LICENSE)
 */
import { Type } from '@angular/core';
import { ServiceBase } from './base.service';
import { Guid } from '@miracledevs/paradigm-ui-web-shared';
export declare type MessageHandler<T> = (message: T) => void | Promise<void>;
/**
 * Represents a message bus registration token.
 */
export declare class RegistrationToken<T> {
    /**
     * A reference to the @see MessageBusService.
     */
    private messageBus;
    /**
     * The inner message type.
     */
    private innerType;
    /**
     * A guid identifying this registration.
     */
    private innerGuid;
    /**
     * Gets the message type.
     */
    readonly type: Type<T>;
    /**
     * Gets the registration guid.
     */
    readonly guid: Guid;
    /**
     * Creates a new instance of @see RegistrationToken
     * @param messageBus a reference to the message bus.
     * @param type the message type.
     */
    constructor(messageBus: MessageBusService, type: Type<T>);
    /**
     * Removes the callback from the message bus.
     */
    unregister(): void;
}
/**
 * Represents a message bus callback handler.
 * It holds a method that must be called when certain
 * message is received.
 */
export declare class MessageBusHandler<T> {
    /**
     * The registration token that identifies this handler.
     */
    private innerToken;
    /**
     * The handler or function that should be called when the message is received.
     */
    private innerHandler;
    /**
     * Gets the registration token that identifies this handler.
     */
    readonly token: RegistrationToken<T>;
    /**
     * Gets the handler function that should be called when the message is received.
     */
    readonly handler: MessageHandler<T>;
    /**
     * Creates a new instance of @see MessageBusHandler
     * @param messageBus a reference to the message bus.
     * @param type the message type.
     * @param handler the message handler.
     */
    constructor(messageBus: MessageBusService, type: Type<T>, handler: MessageHandler<T>);
}
export declare class MessageBusService extends ServiceBase {
    /**
     * A collection of message types and all their handlers or observers.
     */
    private handlers;
    /**
     * Creates a new instance of @see MessageBusService
     */
    constructor();
    /**
     * Gets the amount of messages registered.
     */
    count(): number;
    /**
     * Indicates if the given message type is registered and has handlers associated to it.
     * @param messageType the message type.
     */
    isRegistered<T>(messageType: Type<T>): boolean;
    /**
     * Gets the amount of handler or observers a given message has.
     * @param messageType the message type.
     */
    handlerCount<T>(messageType: Type<T>): number;
    /**
     * Registers a new message handler.
     * The handler will be called every time a message of @see messageType is called.
     * @param messageType the message type.
     * @param handler the message handler.
     */
    register<T>(messageType: Type<T>, handler: MessageHandler<T>): RegistrationToken<T>;
    /**
     * Removes a handler registration from the collection.
     * @param token the registration token.
     */
    unregister<T>(token: RegistrationToken<T>): void;
    /**
     * Unregisters all the message handlers.
     */
    unregisterAll(): void;
    /**
     * Sends a message to all the registered handlers.
     * @param message the message to be sent.
     * @param token if specified, the message will be sent only to one handler.
     */
    send<T>(message: T, token?: RegistrationToken<T>): Promise<boolean>;
}
