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

declare namespace SigApi {
    interface ApiAlarm extends ApiBase {
        /**
         * Returns true if the alarm is active, false otherwise
         *
         * @param {number} varno varno of alarm entry
         * @param {number} [alarmNr] alarmNr of alarm entry
         * @returns {boolean} true if the alarm is active, false otherwise
         */
        isAlarmActive(varno: number, alarmNr?: number): boolean
        /**
         * Returns true if the alarm is inactive, false otherwise
         *
         * @param {number} varno varno of alarm entry
         * @param {number} [alarmNr] alarmNr of alarm entry
         * @returns {boolean} true if the alarm is inactive, false otherwise
         */
        isAlarmInactive(varno: number, alarmNr?: number): boolean
        /**
         * Returns true if the alarm is quit, false otherwise
         *
         * @param {number} varno varno of alarm entry
         * @param {number} [alarmNr] alarmNr of alarm entry
         * @returns {boolean} true if the alarm is quit, false otherwise
         */
        isAlarmQuit(varno: number, alarmNr?: number): boolean
        /**
         * Registered for updates in the alarm list.
         * 
         * An 'ALARMLIST_UPDATE' event and an 'TEMP_ALARM_MGR_ALARM_STATE_CHG' is fired for each update of the alarm list.
         *
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} a promise -> resolve={uid}, reject={uid, status, errortxt}
         * 
         * Returns a Promise, which is resolved with the given uid
         * 
         * If the promises is rejected, an object with uid, status and errortxt is passed in the reject function
         *
         * Possible error for resolve:
         * * 0x0019 -> There are too many clients registered for alarm updates -> it is not possible to register another client
         * * 0x0021 -> This client is already registered for alarm updates
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to register for updates in the alarm list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        registerAlarmUpdate(uid?: number): Promise<{ uid: number }>
        /**
         * Unregistered for updates in the alarm list.
         *
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} a promise -> resolve={uid}, reject={uid, status, errortxt}
         * 
         * Returns a Promise, which is resolved with the given uid
         * 
         * If the promises is rejected, an object with uid, status and errortxt is passed in the reject function
         * 
         * Possible error for resolve:
         * * 0x0020 -> This client is already unregistered for alarm updates
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to unregister for updates in the alarm list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        unregisterAlarmUpdate(uid?: number): Promise<{ uid: number }>
        /**
         * Registered for updates of hot alarms.
         * An 'HOTALARM_UPDATE' and an 'TEMP_ALARM_MGR_HOTALARM_STATE_CHG' event is fired for each update of the spezified hot alarm.
         * 
         * @param {number} type the type of the hot alarm to register for updates Bitmask:
         * * Bit 0 = HotAlarmTimeLast
         * * Bit 1 = HotAlarmPrioHighest
         * * Bit 2 = HotAlarmTimeFirst
         * * Bit 3 = HotAlarmPrioLowest
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} a promise -> resolve={uid, type}, reject={uid, status, errortxt}
         * 
         * Returns a Promise, which is resolved with the given uid and the type of the hot alarm
         * 
         * If the promises is rejected, an object with uid, status and errortxt is passed in the reject function
         *
         * Possible error for resolve:
         * * 0x0019 -> There are too many clients registered for HOT alarm updates -> it is not possible to register another client
         * * 0x0021 -> This client is already registered for HOT alarm updates of the specified type
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to register for updates of hot alarms -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        registerHotAlarmUpdate(
            type: number,
            uid?: number
        ): Promise<{ uid: number, type: number }>
        /**
         * Unregistered for updates of hot alarms
         * 
         * @param {number} type the type of the hot alarm to unregister for updates Bitmask:
         * * Bit 0 = HotAlarmTimeLast
         * * Bit 1 = HotAlarmPrioHighest
         * * Bit 2 = HotAlarmTimeFirst
         * * Bit 3 = HotAlarmPrioLowest
         * @param {number} [uid=undefined] a unique identifier
         * @returns {Promise} a promise -> resolve={uid, type}, reject={uid, status, errortxt}
         * 
         * Returns a Promise, which is resolved with the given uid and the type of the hot alarm
         * 
         * If the promises is rejected, an object with uid, status and errortxt is passed in the reject function
         * 
         * Possible error for resolve:
         * * 0x0020 -> This client is already unregistered for HOT alarm updates of the specified type 
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to unregister for updates of hot alarms -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        unregisterHotAlarmUpdate(
            type: number,
            uid?: number
        ): Promise<{ uid: number, type: number }>
        /**
         * Gets a list of alarm entries
         *
         * @param {number} offset index of the first alarm entry from which gets the list
         * @param {number} itemscount maximum number of returned alarm entries
         * @param {Filter[]|Function} filter array of filter criteria or a user defined filter function
         * 
         * Filter: {key: `string`, value: `number`}
         * 
         * (e.g. [{key: "alarmnr", value: 65530}])
         * @param {Sort|Function} sort sort criteria or a user defined sort function
         * 
         * Sort: {key: `string`, sorttype: `string`}
         * 
         * sorttype:
         * * "asc" for sorted in ascending order
         * * "desc" for sorted in descending order
         * 
         * (e.g. {key: "alarmnr" sorttype: "asc"})
         * @returns {Alarm[]} array of Alarm, that meet the given filter and sort criteria
         *
         * Allowed filter criteria:
         * * {key: "varno", value: a number, invert: a bool} to filter by varno
         * * {key: "alarmnr", value: a number, invert: a bool} to filter by alarm number
         * * {key: "group",  value: a number, invert: a bool} to filter by alarm group
         * * {key: "state",  value: a number, invert: a bool} to filter by alarm state (0=LO, 255=QUIT, 1-254=HI)
         * * {key: "tsHiFirst",  value: {startdate: 'DD.MM.YYYY', starttime: 'HH:MM:SS', enddate: 'DD.MM.YYYY', endtime: 'HH:MM:SS', invert: a bool}} to filter by the time stamp of the first incoming alarm
         * * {key: "tsHiLast",  value: {startdate: 'DD.MM.YYYY', starttime: 'HH:MM:SS', enddate: 'DD.MM.YYYY', endtime: 'HH:MM:SS', invert: a bool}} to filter by the time stamp of the last incoming alarm
         * * {key: "tsLo",  value: {startdate: 'DD.MM.YYYY', starttime: 'HH:MM:SS', enddate: 'DD.MM.YYYY', endtime: 'HH:MM:SS', invert: a bool}} to filter by the time stamp of the outgoing alarm
         * * {key: "tsQuit",  value: {startdate: 'DD.MM.YYYY', starttime: 'HH:MM:SS', enddate: 'DD.MM.YYYY', endtime: 'HH:MM:SS', invert: a bool}} to filter by the time stamp of the acknowledged alarm
         * * {key: "num",  value: a number, invert: a bool} to filter by the number of alarms
         * * {key: "data",  value: a string, invert: a bool} to filter by alarm data
         * 
         * if invert is true, the result of the filter criteria is inverted
         */
        getAlarmEntries(
            offset: number,
            itemscount: number,
            filter?: AlarmFilter[] | ((event: Alarm) => boolean),
            sort?: AlarmSort | ((a: Alarm, b: Alarm) => number),
        ): Alarm[]
        /**
         * Gets the length of the alarm entry list
         *
         * @returns {number} number of alarms in the list
         */
        getAlarmListLength(): number
        /**
         * Gets a alarm entry
         * 
         * @param {number} varno varno of alarm entry
         * @param {number} [alarmNr] alarmNr of alarm entry
         * @returns {Alarm|null}
         */
        getAlarmEntry(varno: number, alarmNr?: number): Alarm | null
        /**
         * Gets the maximum length of the alarm entry list
         *
         * @returns {number} maximum number of alarms in the list
         */
        getMaxAlarmListLength(): number
        /**
         * Gets the hot alarm for the given type
         *
         * @param {number} type the type of the hot alarm
         * * 1 = HotAlarmTimeLast
         * * 2 = HotAlarmPrioHighest
         * * 4 = HotAlarmTimeFirst
         * * 8 = HotAlarmPrioLowest
         * @returns {Alarm|null} the hot alarm for the given type or null, if not set
         */
        getHotAlarm(type: number): Alarm | null
        /**
         * Deletes alarm entries in the alarm entry list with the specified varno and state
         * 
         * @param {number[]|object[]} alarms an array with the varno of the alarm entries to be deleted
         *                                   object: { {number} varNo, {number} alarmNr }
         * @param {number} [state=0] the state of the alarm
         * 
         * Bitmask:
         * * 0 = all alarms
         * * Bit 0 = alarm state is QUIT
         * * Bit 1 = alarm state is LO)
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} a promise -> resolve={uid, [varno, status]}, reject={uid, status, errortxt}
         * 
         * A promise that is resolved with varno and status for each deleted alarm entry or rejected with an status and an errortext.
         * 
         * Possible error for resolve:
         * * 0x0020 -> A alarm with the specified varno could not be found -> check the alarms varno
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to delete a entry from the alarm entry list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running 
         */
        deleteAlarms(
            alarms: number[] | object[],
            state?: number,
            uid?: number
        ): Promise<{ uid: number, varno?: number, status?: number } | { uid: number, varno: number, status: number }[]>
        /**
         * Deletes alarm entries in the alarm entry list with the specified state
         * 
         * @param {number} [state=0] the state of the alarm
         * 
         * Bitmask:
         * * 0 = all alarms
         * * Bit 0 = alarm state is QUIT
         * * Bit 1 = alarm state is LO)
         * @param {number} [uid=undefined] a unique identifier
         * 
         * @returns {Promise} a promise -> resolve={uid}, reject={uid, status, errortxt}
         * 
         * A promise that will be resolved if the alarm list is successfully deleted.
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to delete all entries from the alarm entry list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        deleteAllAlarms(state?: number, uid?: number): Promise<{ uid: number }>
        /**
         * Hide all alarm entries with the spezified varno in the alarm entry list.
         * Has an effect only for this session, after reloading all alarms are visible again.
         *
         * @param {number[]|object[]} alarms an array with the varno of the alarm entries to be hidden
         *                                   object: { {number} varNo, {number} alarmNr }
         */
        hideAlarms(alarms: number[] | object[]): void
        /**
         * Unhide all alarm entries in the alarm entry list
         */
        unhideAllAlarms(): void
        /**
         * Quits alarm entries with the spezified varno in the alarm entry list
         *
         * @param {number[]|object[]} alarms an array of varno of alarm entries to quit
         *                                   object: { {number} varNo, {number} alarmNr }
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} a promise -> resolve={uid, result}, reject={uid, status, errortxt}
         * 
         * (result = Array of {varno, status, errortxt})
         * 
         * errortxt is '' if status = 0
         * 
         * A promise that is resolved with varno and status for each quit alarm entry or rejected with an uid, an status and an errortext.
         *
         * Possible error for resolve:
         * * 0x0020 -> A alarm with the specified varno could not be found -> check the alarms varno
         * 
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to quit an alarm from the alarm entry list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         * * 0x0002 -> ERROR_INVALID_VARNO -> the given varno is invalid -> check the varno
         */
        quitAlarms(
            alarms: number[] | object[],
            uid?: number
        ): Promise<{ uid: number, result: { varno: number, status: number, errortxt: string }[] }>
        /**
         * Quits all alarm entries in the alarm entry list
         *
         * @param {number} [uid=undefined] a unique identifier
         *
         * @returns {Promise} a promise -> resolve={uid, result}, reject={uid, status, errortxt}
         * 
         * (result = Array of {station, status, errortxt})
         * 
         * errortxt is '' if status = 0
         * 
         * A promise that is resolved with station and status for all stations whose journal entries successfully quit or rejected with an uid, an status and an errortext.
         *
         * Possible status for reject:
         * * 0x0001 -> ERROR_UNKNOWN -> Unknown error: see errortext for details
         * * 0x0012 -> ERROR_INSUFFICIENT_PRIVILEGES -> not enough privileges to quit all alarms from the alarm entry list -> check the access level of the current user
         * * 0x0007 -> ERROR_COMMUNICATION -> no response from dataservice for this request -> check if the DS is running
         */
        quitAllAlarms(
            uid?: number
        ): Promise<{ uid: number, result: { varno: number, status: number, errortxt: string }[] }>
        /**
         * Function to check if parameter object is a instanceof Alarm.
         * This function can be used without importing the type Alarm to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof Alarm, else false
         */
        instanceofAlarm(object: any): boolean
    }
}
