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

declare namespace SigApi {
    interface ApiState extends ApiBase {
        /**
         * Used to register for changing a specified status. After registration and when the specified state changes, an 'events.int.STATE_CHANGED' event is triggered.
         *
         * @param {number} target Bit mask for determining the targets (= whose status change)
         * * Bit 1 ... DataService (sigApi.SIG_CONST.STATION_STATE_TARGET_DATASERVICE)
         * @param {number} type   The status type (= which status change)
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST)
         * 
         *   => event 'events.int.STATE_CHANGED' {@link SigState} 'data' contains the {Uint32} station number (offset: 0) and {Uint32} state (offset: 4)
         * @param {object|DataView|ArrayBuffer} data Additional data depending on type.
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST):
         *  * {object}:
         * 
         *    { {number} station }
         *  * {DataView|ArrayBuffer}:
         * 
         *    {Uint32} station number (offset: 0)
         * @param {number} [uid=undefined] a unique identifier 
         *
         * @returns {Promise} Promise -> resolve: ({uid: number, status: number}) => void, reject: ({uid: number, status: number, errortxt: string}) => void 
         * 
         * A Promise that is resolved with an Object containing the identifier as attribute uid and a statuscode as attribute status.
         * If the status code is 0, the registration was successful and an event 'events.int.STATE_CHANGED' is triggered on a corresponding status change.
         * This event has the following structure: ({target: number, type: number, data: DataView}) where the content of data depends on type (see definition above)
         * 
         * The reject Function is called with an object that has the identifier as attribute uid, a statuscode as attribute status, and an errortext as attribute errortxt
         *
         * Possible status for reject: 
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to registers for a status change -> check the access level of the current user
         * * 0x0044 -> ERROR_INVALID_PARAMETER -> invalid parameter: see errortext for details
         */
        registerState(
            target: number,
            type: number,
            data: object | DataView | ArrayBuffer,
            uid?: number
        ): Promise<{ uid: number, status: number }>
        /**
         * Used to unregister for changing a specified status
         *
         * @param {number} target Bit mask for determining the targets (= whose status change)
         * * Bit 1 ... DataService (sigApi.SIG_CONST.STATION_STATE_TARGET_DATASERVICE)
         * @param {number} type   The status type (= which status change)
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST)
         * 
         *   => event 'events.int.STATE_CHANGED' {@link SigState} 'data' contains the {Uint32} station number (offset: 0) and {Uint32} state (offset: 4)
         * @param {object|DataView|ArrayBuffer} data Additional data depending on type.
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST):
         *  * {object}:
         * 
         *    { {number} station }
         *  * {DataView|ArrayBuffer}:
         * 
         *    {Uint32} station number (offset: 0)
         * @param {number} [uid=undefined] a unique identifier 
         *
         * @returns {Promise} Promise -> resolve: ({uid: number, status: number}) => void, reject: ({uid: number, status: number, errortxt: string}) => void 
         * 
         * A Promise that is resolved with an Object containing the identifier as attribute uid and a statuscode as attribute status
         * 
         * The reject Function is called with an object that has the identifier as attribute uid, a statuscode as attribute status, and an errortext as attribute errortxt
         *
         * Possible status for reject: 
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to registers for a status change -> check the access level of the current user
         * * 0x0044 -> ERROR_INVALID_PARAMETER -> invalid parameter: see errortext for details
         */
        unregisterState(
            target: number,
            type: number,
            data: object | DataView | ArrayBuffer,
            uid?: number
        ): Promise<{ uid: number, status: number }>
        /**
         * Gets a specified status
         *
         * @param {number} target Bit mask for determining the targets (= whose status)
         * * Bit 1 ... DataService (sigApi.SIG_CONST.STATION_STATE_TARGET_DATASERVICE)
         * @param {number} type   The status type (= which status change)
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST)
         * 
         *   => event 'events.int.STATE_CHANGED' {@link SigState} 'data' contains the {Uint32} station number (offset: 0) and {Uint32} state (offset: 4)
         * @param {object|DataView|ArrayBuffer} data Additional data depending on type.
         * * LasalIdList (sigApi.SIG_CONST.STATION_STATE_TYPE_LASALID_LIST):
         *  * {object}:
         * 
         *    { {number} station }
         *  * {DataView|ArrayBuffer}:
         * 
         *    {Uint32} station number (offset: 0)
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} Promise -> resolve: ({uid: number, status: number, data: DataView, station: number, state: number}) => void, reject: ({uid: number, status: number, errortxt: string}) => void 
         * 
         * A Promise that is resolved with an Object containing the identifier as attribute uid, a statuscode as attribute status and, if status = 0, the target, the type and 
         * the returned data as data depending on type (see definition above). If status != 0, data = null.
         * 
         * The reject Function is called with an object that has the identifier as attribute uid, a statuscode as attribute status, and an errortext as attribute errortxt
         *
         * Possible status for reject: 
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to registers for a status change -> check the access level of the current user
         * * 0x0044 -> ERROR_INVALID_PARAMETER -> invalid parameter: see errortext for details
         */
        getState(
            target: number,
            type: number,
            data: object | DataView | ArrayBuffer,
            uid?: number
        ): Promise<{ uid: number, status: number, data: DataView, station: number, state: number }>
    }
}
