import { CoreModelDefinition } from "../models/coremodel.js";
import { Queue } from "../queues/queueservice.js";
import { Service, ServiceParameters } from "./service.js";
/**
 * AsyncEvent representation
 */
export declare class AsyncEvent {
    /**
     * Service emitted the event
     */
    service: string;
    /**
     * Type of event
     */
    type: string;
    /**
     * Payload of the event
     */
    payload: any;
    /**
     * Time
     */
    time: Date;
    /**
     * Used when serializing a service
     */
    static ServiceTag: string;
    constructor(service: string | Service | CoreModelDefinition, type: any, payload?: {});
    /**
     * Allow payload to contain Service but do not serialize them
     * replacing them by a #Webda:Service:${service.getName()} so it
     * can be revived
     *
     * @returns
     */
    toJSON(): this & {
        payload: string;
    };
    /**
     * Deserialize from the queue, reviving any detected service
     *
     * @param data
     * @param service
     * @returns
     */
    static fromQueue(data: any, service: Service): AsyncEvent;
    /**
     * Mapper name
     * @returns
     */
    getMapper(): string;
}
interface QueueMap {
    [key: string]: Queue;
}
/**
 * @inheritdoc
 */
export declare class EventServiceParameters extends ServiceParameters {
    /**
     * Queues to post async events to
     */
    queues?: {
        [key: string]: string;
    };
    /**
     * Make the event sending asynchronous
     */
    sync?: boolean;
    /**
     * @inheritdoc
     */
    constructor(params: any);
}
/**
 * @category CoreServices
 * @WebdaModda AsyncEvents
 */
declare class EventService<T extends EventServiceParameters = EventServiceParameters> extends Service<T> {
    _callbacks: any;
    _queues: QueueMap;
    _defaultQueue: string;
    _async: boolean;
    /**
     * Load parameters
     *
     * @param params
     * @ignore
     */
    loadParameters(params: any): ServiceParameters;
    /**
     * @ignore
     * Setup the default routes
     */
    computeParameters(): Promise<void>;
    /**
     * Bind a asynchronous event
     *
     * ```mermaid
     * sequenceDiagram
     *  participant S as Service
     *  participant As as AsyncEventService
     *  participant Q as Queue
     *  participant Aw as AsyncEventService Worker
     *
     *  As->>S: Bind event to a sendQueue listener
     *  activate As
     *  S->>As: Emit event
     *  As->>Q: Push the event to the queue
     *  deactivate As
     *  Aw->>Q: Consume queue
     *  Aw->>Aw: Call the original listener
     * ```
     *
     * @param service
     * @param event
     * @param callback
     * @param queue
     */
    bindAsyncListener(service: Service | CoreModelDefinition, event: string, callback: any, queue?: string): void;
    /**
     * Synchronous Listener to proxy to async
     *
     * @param service
     * @param type
     * @param queue
     * @param payload
     * @returns
     */
    pushEvent(service: Service | CoreModelDefinition, type: string, queue: string, payload: any): Promise<void>;
    /**
     * Process one event
     *
     * @param event
     * @returns
     */
    protected handleEvent(event: AsyncEvent): Promise<void>;
    /**
     *
     * @param eventBody serialized event
     * @returns
     */
    protected handleRawEvent(event: AsyncEvent): Promise<void>;
    /**
     * Process asynchronous event on queue
     * @param queue
     * @returns
     */
    worker(queue?: string): Promise<void>;
}
export { EventService, QueueMap };
