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

declare namespace SigApi {
    interface ApiSigUtils extends ApiBase {
        /**
         * Converts date and time from the Sigmatek format to a string.
         * 
         * @param {number} date The data in the Sigmatek date format
         * @param {number} time The time in the Sigmatek time format
         * @param {string} [datedelimiter='.'] The delimiter which should be put in the date (default: ".")
         * @param {string} [timedelimiter=':'] The delimiter which should be put in the time (default: ":")
         * @param {string} [delimiter=' '] The delimiter which should be put between the date and the time (default: " ")
         * 
         * @returns {string} The converted date and time as String
         */
        getSigDateTimeAsString(
            date: number,
            time: number,
            datedelimiter?: string,
            timedelimiter?: string,
            delimiter?: string
        ): string
        /**
         * Converts date from the Sigmatek format to a string.
         * 
         * @param {number} date The data in the Sigmatek date format
         * @param {string} [datedelimiter='.'] The delimiter which should be put in the date (default: ".")
         * 
         * @returns {string} The converted date as String
         */
        getSigDateAsString(date: number, datedelimiter?: string): string
        /**
         * Converts a string to a date in the Sigmatek format as a Number.
         * 
         * @param {string} date The date as String
         * @param {string} [datedelimiter='.'] The delimiter which is used in the date string (default: ".")
         * 
         * @returns {number} The date in the Sigmatek date format as a Number
         */
        getSigDateAsNumber(date: string, datedelimiter?: string): number
        /**
         * Converts time from the Sigmatek format to a string.
         * 
         * @param {number} time The time in the Sigmatek time format
         * @param {string} [timedelimiter=':'] The delimiter which should be put in the time (default: ":")
         * 
         * @returns {string} The converted time as String
         */
        getSigTimeAsString(time: number, timedelimiter?: string): string
        /**
         * Converts a string to a time in the Sigmatek format as a Number.
         * 
         * @param {string} time The time as String
         * @param {string} [timedelimiter=':'] The delimiter which is used in the time string (default: ":")
         * 
         * @returns {number} The time in the Sigmatek time format as a Number
         */
        getSigTimeAsNumber(time: string, timedelimiter?: string): number
        /**
         * Generates a unique identifier.
         * 
         * A UID must be deleted (deleteUID) when it is not required anymore.
         * 
         * @returns {number} The resulting unique identifier.
         */
        getUID(): number
        /**
         * Deletes a previously generated unique identifier.
         * 
         * @param {number} uid The uid to delete
         * @returns {boolean} The result of the delete operation
         */
        deleteUID(uid: number): boolean
        /**
         * This function may throw an error if parameter obj can not be iterated by a for...in statement.
         * @param {object} obj A object to copy
         * @returns {object} The copy of an object, undefined if parameter obj is undefined, null if parameter obj is null.
         */
        copyObject(obj: object): any
        /**
         * This function throws an error if parameter array can not be iterated
         * @param {any[]} array An array to copy
         * @returns {any[]} The copy of an array
         */
        copyArray(array: any[]): any[]
        /**
         * Calculate CRC16
         * 
         * @param {number[]} buffer The input buffer for the CRC algorithm
         * @param {number} [initval=0] The initial/seed value for the CRC algorithm
         * @returns {number} The calculated CRC16
         */
        crc16(buffer: number[], initval?: number): number
        /**
         * Calculate CRC32
         * 
         * @param {number[]} buffer The input buffer for the CRC algorithm
         * @param {number} [initval=0] The initial/seed value for the CRC algorithm
         * @returns {number} The calculated CRC32
         */
        crc32(buffer: number[], initval?: number): number
        /**
         * Enqueues a callback which will be run before the next render, at
         * `requestAnimationFrame` timing.
         * This method is useful for enqueuing work that requires DOM measurement,
         * since measurement may not be reliable in custom element callbacks before
         * the first render, as well as for batching measurement tasks in general.
         * 
         * Don't use this API for component development! 
         * Import SigPolymer from '../sig-element/sig-element.js' and call SigPolymer.beforeNextRender(context, callBack) instead!
         *  
         * @param {object} context Context Object that enqueued the callback (usually 'this')
         * @param {Function} callBack Callback Function that will be called before the next render cycle
         */
        beforeNextRender(context: any, callBack: Function): void
        /**
         * Enqueues a callback which will be run after the next render, equivalent
         * to one task (`setTimeout`) after the next `requestAnimationFrame`.
         * This method is useful for tuning the first-render performance of an
         * element or application by deferring non-critical work until after the
         * first paint.  Typical non-render-critical work may include adding UI
         * event listeners and aria attributes.
         * 
         * Don't use this API for component development! 
         * Import SigPolymer from '../sig-element/sig-element.js' and call SigPolymer.afterNextRender(context, callBack) instead!
         * 
         * @param {object} context Context Object that enqueued the callback (usually 'this')
         * @param {Function} callBack Callback Function that will be called after the next render cycle
         */
        afterNextRender(context: any, callBack: Function): void
        /**
         * Sets the timeout and returns the timeout ID.
         * @param {object} context The context, in which the timeout is to be set and saved. The context itself does not influence the context, in which the handler is executed. It only serves as a key in a Map() in which the timeouts are stored. Normally, pass the reference to the current instance (this).
         * @param {Function} handler The function that will be executed after the given delay.
         * @param {number} [delay=0] The number of milliseconds to wait before executing the code.
         * @returns {number|boolean} Returns the ID of the setTimeout(). Use this value with the sigUtils.clearTimeout() method to cancel the timeout. Returns false, if the parameters are wrong.
         */
        setTimeout(
            context: any,
            handler: Function,
            delay?: number
        ): number | boolean
        /**
         * Clears the timeout with the timeout ID and the given context.
         * @param {object} context The context in which the timeout was set.
         * @param {number} timeoutId The ID value of the timeout returned by the API setTimeout() method.
         * @returns {boolean} True if the timeout was cleared, false if the parameters are wrong or there is no timeout with such ID.
         */
        clearTimeout(context: any, timeoutId: number): boolean
        /**
         * Clears all the timeouts of the given context. Note that this function is automatically called for every component / code module, before they are destroyed by the Runtime (e.g. on dashboard change). 
         * There is therefore no need to call this function in disconnectedCallback().
         * @param {object} context The context in which the timeouts were set.
         * @returns {boolean} True if timeouts were cleared, otherwise false.
         */
        clearAllTimeouts(context: any): boolean
        /**
         * Sets a new interval and saves it to the intervals map. The interval ID needs to be saved so that the interval can be cleared before its context is destroyed (e.g. on dashboard change).
         * @param {object} context A context, in which the interval is to be set and saved. The context itself does not influence the context, in which the handler is executed. It only serves as a key in a Map() in which the intervals are stored. Normally, pass the reference to the current instance (this).
         * @param {Function} handler The interval function executed at specified intervals.
         * @param {number} [interval=0] The interval (in milliseconds) on how often to execute the code. 
         * @returns {number|boolean} A Number, representing the ID value of the interval that is set. Use this value with the sigUtils.clearInterval() method to cancel the interval. If the parameters are wrong, false is returned.
         */
        setInterval(
            context: any,
            handler: Function,
            interval?: number
        ): number | boolean
        /**
         * Clears the interval with the interval ID and the given context.
         * @param {object} context The context in which the interval was set.
         * @param {number} intervalId The ID of the interval returned by the setInterval() method.
         * @returns {boolean} True if the interval was cleared, false if the parameters are wrong or there is no interval with such ID.
         */
        clearInterval(context: any, intervalId: number): boolean
        /**
         * Clears all intervals of the given context. Note that this function is automatically called for every component / code module, before they are destroyed by the Runtime (e.g. on dashboard change). 
         * There is therefore no need to call this function in disconnectedCallback(). 
         * @param {object} context The context in which the intervals were set.
         * @returns {boolean} Returns true if the intervals were cleared, false if the parameters are wrong.
         */
        clearAllIntervals(context: any): boolean
        /**
         * Registers the promise with the given context so that it can be rejected before the context is removed from DOM.
         * @param {object} context A context, in which the promise is saved. The context itself does not influence the context, in which the promise is executed. It only serves as a key in a Map() in which the promises are stored. 
         * Normally, pass the reference to the current instance (this) 
         * @param {Promise} promise The promise to be registered.
         * @param {Function} [resolve] The resolve callback of the promise. This parameter is not mandatory, as long as the resolve callback is already saved in the promise object in the property **resolvePromise**. Promises returned by Runtime API functions already have this property set.
         * @param {Function} [reject] The reject callback of the promise. This parameter is not mandatory, as long as the reject callback is already saved in the promise object in the property **rejectPromise**. Promises returned by Runtime API functions already have this property set.
         * @returns {boolean} Returns true if the promise was registered, false if the parameters were wrong.
         */
        registerPromise(
            context: any,
            promise: Promise<any>,
            resolve?: Function,
            reject?: Function
        ): boolean
        /**
         * Rejects all pending promises saved in the promises array of the given context. Note that this function is automatically called for every component / code module, before they are destroyed by the Runtime (e.g. on dashboard change). 
         * There is therefore no need to call this function in disconnectedCallback(). 
         * @param {object} context The context in which the promises were set.
         * @returns {boolean} Returns true if the promise were rejected, false if the parameter is wrong or there are no registered promises.
         */
        rejectAllPendingPromises(context: any): boolean
        /**
         * Adds event listener and registers the event into registered events array.
         * @param {object} context A context, in which the event listener is to be set and saved. The context itself does not influence the context, in which the event handler is executed. It also does NOT serve as a target that receives events or has event listeners. 
         * It only serves as a key in a Map() in which the event listeners are stored. Normally, pass the reference to the current instance (this).
         * @param {string|object} event A case-sensitive string representing the event type to listen for (mouseout, APPROUTE_CHG, LANGUAGE_CHG, etc.). 
         * or an object containing major and minor ID for the runtime event.
         * @param {Function} handler The event handler that is executed when the event is fired.
         * @param {string} [type='jsEvent'] The basic event type (jsEvent, runtimeEvent, runtimeUserEvent, polymerEvent).
         * @param {object} [target={}] The event target (this, window, tbody, etc.).
         * @param {object} [options={}] The event options.
         * @returns {number|boolean} In case of runtimeEvent being added the UID of Runtime event will be returned. False is returned if the parameters are wrong.
         */
        addEventListener(
            context: any,
            event: string | object,
            handler: Function,
            type?: string,
            target?: object,
            options?: object
        ): number | boolean
        /**
        * Removes event listener and removes the event from the registered events array.
        * @param {object} context The context, in which the event listener was registered.
        * @param {string|object} event A case-sensitive string representing the event type (mouseout, APPROUTE_CHG, LANGUAGE_CHG, etc.) or an object containing major and minor ID for the runtime event.
        * When the type of event listener is runtimeEventById, event is an object with maId and miId.
        * @param {Function|number} handler The event handler or UID for runtimeEvent.
        * @param {string} [type=jsEvent] The basic event type (jsEvent, runtimeEvent, runtimeUserEvent, polymerEvent).
        * @param {object} [target={}] The event target (this, window, tbody, etc.).
        * @param {object} [options={}] The event options.
        * @returns {boolean} True if the event listener was removed, otherwise false.
        */
        removeEventListener(
            context: any,
            event: string | object,
            handler: Function | number,
            type?: string,
            target?: object,
            options?: object
        ): boolean
        /**
         * Removes all event listeners, that were previously registered using sigUtils.addEventListener(). Note that this function is automatically called for every component / code module, before they are destroyed by the Runtime (e.g. on dashboard change). 
         * There is therefore no need to call this function in disconnectedCallback().
         * @param {object} context The context, in which the event listeners were registered.
         * @returns {boolean} True if event listeners were cleared, otherwise false.
         */
        removeAllEventListeners(context: any): boolean
        /**
         * Clears all event listeners, timeouts, intervals and rejects all pending promises in the given context. 
         * Note that this function is automatically called for every component / code module, before they are destroyed by the Runtime (e.g. on dashboard change). 
         * There is therefore no need to call this function in disconnectedCallback(). 
         * @param {object} context Context that should cleared.
         * @returns {boolean} True, if the context is is defined, otherwise false.
         */
        clearAll(context: any): boolean
        /**
         * Globally handles inactive interaction of controls.
         * If a callback has been registered by addGlobalHandleInactiveInteractionCallback
         * the callback is called, otherwise the internal runtime event CONTROL_INACTIVE_INTERACTION
         * is fired.
         * @param {Event} event The event to be handled
         * @returns {Promise|null} A Promise that is expected to resolve when the inactive
         *                         interaction has been handled.
         *                         (e.g. the alert window has been closed)
         */
        handleGlobalInactiveInteraction(event: globalThis.Event): Promise | null
        /**
         * Registers the callback to be called by handleGlobalInactiveInteraction.
         * @param {Function} callback ({Event} event): {Promise|null}
         */
        addGlobalHandleInactiveInteractionCallback(callback: (event: globalThis.Event) => Promise | null): void
        /**
         * Removes the previously registered callback to be called by handleGlobalInactiveInteraction.
         */
        removeGlobalHandleInactiveInteractionCallback(): void
        /**
         * Globally manipulate if sigHandleInactiveInteraction should be called for the event.
         * If a callback has been registered by addGlobalInterceptInactiveInteractionEventCallback
         * the callback is called, otherwise the default implementation: `(event.type === 'pointerup')`
         * is in effect.
         * @param {Event} event The event to be intercepted
         * @returns {boolean} True, if sigHandleInactiveInteraction should be called
         */
        interceptGlobalInactiveInteractionEvent(event: globalThis.Event): boolean
        /**
         * Registers the callback to be called by interceptGlobalInactiveInteractionEvent.
         * @param {Function} callback ({Event} event): {boolean}
         */
        addGlobalInterceptInactiveInteractionEventCallback(callback: (event: globalThis.Event) => boolean): void
        /**
         * Removes the previously registered callback to be called by interceptGlobalInactiveInteractionEvent.
         */
        removeGlobalInterceptInactiveInteractionEventCallback(): void
        /**
         * Registers events to being handled by InactiveInteractionManager.
         * List of eventNames registered by default:
         * `'down', 'up', 'tap', 'track', 'longpress', 'pinchZoom',
         *  'click', 'dblclick', 'mousedown', 'mouseup', 'mousemove',
         *  'touchstart', 'touchmove', 'touchend', 'touchcancel',
         *  'pointerdown', 'pointerup', 'pointermove', 'pointercancel'`
         * @param {string|string[]} eventName A eventName or a list of eventNames to be registered
         */
        addGlobalInactiveInteractionEventHandler(eventName: string | string[]): void
        /**
         * Removes previously registered events from being handled by InactiveInteractionManager.
         * @param {string|string[]} eventName A eventName or a list of eventNames to be removed
         */
        removeGlobalInactiveInteractionEventHandler(eventName: string | string[]): void
    }
}
