/// <reference path="./sigApi.ApiBase.d.ts" />
/// <reference path="./sigApi.Event.d.ts" />

declare namespace SigApi {
    interface ApiEventMediator extends ApiBase {
        /**
         * Adds an EventListener
         * 
         * @param {Event} event the event on which should be listened (from EventAPI)
         * @param {Function} subscriber the callback function
         * 
         * function: (`number`, `number`, `any`)
         * @param {number} [src=undefined] the source from the event on which should be listened (0 = intern, 1 = extern, 2 (default) = both)
         * 
         * @returns {number} a unique identifier which is used to unsubscribe the EventListener
         */
        subscribe(
            event: Event,
            subscriber: (maId: number, miId: number, message: any, data: any) => void,
            src?: number
        ): number
        /**
         * Adds an EventListener
         * 
         * @param {number} maId the maId of the Event
         * @param {number} miId the miId of the Event
         * @param {Function} subscriber the callback function
         * 
         * function: (`number`, `number`, `any`)
         * @param {number} [src=SIG_CONST.EVENT_SRC_BOTH] the source from the event on which should be listened (0 = intern, 1 = extern, 2 (default) = both)
         * 
         * @returns {number} a unique identifier which is unsed to unsubscribe the EventListener
         */
        subscribeWithId(
            maId: number,
            miId: number,
            subscriber: (maId: number, miId: number, message: any, data: any) => void,
            src?: number
        ): number
        /**
         * Removes an EventListener
         * 
         * @param {Event} event the event on which the EventListener was registrated (from EventAPI)
         * @param {number} id the id given on the event registration
         */
        unsubscribe(event: Event, id: number): void
        /**
         * Removes an EventListener
         * 
         * @param {number} maId the maId of the Event
         * @param {number} miId the miId of the Event
         * @param {number} id the id given on the event registration
         */
        unsubscribeWithId(maId: number, miId: number, id: number): void
        /**
         * Publishes an event
         * 
         * @param {Event} event the event which should be published (from EventAPI)
         * @param {any} message parameter for the event
         */
        publish(event: Event, message: any): void
        /**
         * Publishes an event
         * 
         * @param {number} maId the maId of the Event
         * @param {number} miId the miId of the Event
         * @param {any} message parameter for the event
         */
        publishWithId(maId: number, miId: number, message: any): void
        /**
         * Publishes an event
         * 
         * @param {Event} event the event which should be send
         * @param {number} dest the destination number (stationNr, sessionId or broadcast address)
         * @param {DataView} [data=undefined] the data as DataView (not required)
         * @param {number} [uid=undefined] a unique identifier (not required)
         * 
         * @returns {Promise} Promise -> resolve(), reject(string)
         * 
         * A Promise which is resolve when the DS acknowledges the reception of the frame
         * 
         * If the promises gets rejected, a string with the reason is given as parameter
         */
        publishToStation(
            event: Event,
            dest: number,
            data?: DataView,
            uid?: number
        ): Promise<void>
        /**
         * Publishes an event
         * 
         * @param {number} maId the maId of the Event
         * @param {number} miId the miId of the Event
         * @param {number} dest the destination number (stationNr, sessionId or broadcast address)
         * @param {DataView} [data=undefined] the data as DataView (not required)
         * @param {number} [uid=undefined] a unique identifier (not required)
         * 
         * @returns {Promise} Promise -> resolve(), reject(string)
         * 
         * A Promise which is resolve when the DS acknowledges the reception of the frame
         * 
         * If the promises gets rejected, a string with the reason is given as parameter
         */
        publishToStationWithId(
            maId: number,
            miId: number,
            dest: number,
            data?: DataView,
            uid?: number
        ): Promise<void>
    }
}
