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

declare namespace SigApi {
    interface ApiTextManager extends ApiBase {
        /**
         * Sets the current language
         * 
         * @param {number} index The index of the number to switch to
         */
        setLanguage(index: number): void
        /**
         * Returns an array of text list names.
         * 
         * @returns {string[]}
         */
        getTextListNames(): string[]
        /**
         * Returns an array of text names.
         * 
         * @param {string} textList The name of the textlist
         * @returns {string[]}
         */
        getTextNames(textList: number | string): string[]
        /**
         * Gets a localized text from a textlist with the preferred language. 
         * If the text is not found in that language, the text is given in english and if no english version is found,
         * the text is given in the next available language
         * @async
         * @param {string} textList The name of the textlist
         * @param {string} text The aliasname of the text
         * @param {number} [language=undefined] The index of the preferred language.
         * 
         * @returns {Promise<string>} resolve({string} the text from the textlist)
         */
        getTextAsync(
            textList: number | string,
            text: number | string,
            language?: number
        ): Promise<string>
        /**
         * Gets more localized texts from one or more textlists at once. The rules for the language are the same as for getText() (preferredLanguage -> english -> any).
         * If the requested texts was not found in any language, the default text could be given in the requestObject.
         * 
         * Supports an alternative interface for texts with parameters:
         * For texts with parameters in the requestObj instead of `{string} defaultText` a array of `{@see PropertyObject} propObj`
         * for the text parameters can be provided.
         * @async
         * @param {object} requestObj A object to describe which texts should be returned. (This object gets modified with the found texts)
         * 
         * For example:
         * ```
         *     {
         *         textList1: {
         *             textName1: 'defaultText1',
         *             textName2: 'defaultText2',
         *             ...
         *         },
         *         textList2: {
         *             textName3: 'defaultText3',
         *             ...
         *         },
         *         ...
         *     }
         * ```
         * 
         * Alternative interface example for text containing a '%s' text placeholder:
         * ```
         *     {
         *         textList1: {
         *             textName1: [
         *                 {
         *                     src: sigApi.SIG_CONST.PROP_SRC_DATAPOINT,
         *                     dest: sigApi.SIG_CONST.PROP_DEST_NONE,
         *                     value: 84 // {number} dpId
         *                 }
         *             ]
         *          }
         *     }
         * ```
         * @param {number} [language=undefined] The index of the preferred language.
         * 
         * @returns {Promise} resolve({object} The requestObject where the defaultTexts are replaced with the found texts)
         */
        getTextsAsync(requestObj: object, language?: number): Promise<any>
        /**
         * Gets a localized text, where the supported escape sequence (%any, %xany) gets replacted with the given values in the param array.
         * The rules for the language are the same as for getText() (preferredLanguage -> english -> any).
         * @async
         * @param {object} descObj A object to describe which texts with which parameter should be returned
         * 
         * For example:
         * ```
         *     {
         *         textList: 'textListName', //Name of the textlist
         *         text: 'textName',         //Name of the text
         *         param: [                  //Values with which the escape sequences gets replaced
         *             'replText', 
         *             ...
         *         ]
         *     }
         * ```
         * In Designer Runtime, the _param_ property is ignored and no string sequences are replaced.
         * @param {number} [language=undefined] The index of the preferred language.
         * 
         * @returns {Promise} resolve({string} The found text where the escape sequences got replaced)
         */
        getTextWithParameterAsync(
            descObj: object,
            language?: number
        ): Promise<string>
        /**
         * Gets an description object for the current language
         * @async
         * @returns {Promise<Language>} resolve({Language} A object representing the current language)
         */
        getCurrentLanguageAsync(): Promise<Language>
        /**
         * Sets the current language. In Designer Runtime, this method is not implemented.
         * @async
         * @param {number} index The index of the number to switch to
         * 
         * @returns {Promise<void>} Returns an empty promise
         */
        setLanguageAsync(index: number): Promise<void>
        /**
         * Returns an list of all Languages in the RT
         * @async
         * @returns {Promise<Language>} resolve({Language[]} an list of all language objects in the RT)
         */
        getLanguagesAsync(): Promise<Language[]>
        /**
         * Sets a text. For this feature to work the 'Observe' checkbox of the text list needs to be set.
         * 
         * @param {string} textList The name of the textlist
         * @param {string} text The aliasname of the text
         * @param {string} data The string to be set
         * @param {number} [language=undefined] The index of the preferred language.
         * @param {boolean} [persistInFile=false] Persist text in file
         * @param {boolean} [sendToAllClients=false] Send text to all clients
         * @returns {object} { {number} status, {string|undefined} errortxt, {Promise|undefined} persistInFilePromise }
         */
        setText(
            textList: number | string,
            text: number | string,
            data: string,
            language?: number,
            persistInFile?: boolean,
            sendToAllClients?: boolean
        ): { status: number, errortxt?: string, persistInFilePromise?: Promise }
        /**
         * Adds an observer on a text
         * 
         * @param {string} textList The name of the textlist
         * @param {string} text The aliasname of the text
         * @param {Function} callback ({number} textListIndex, {number} textIndex, {string} text, {number} language): void
         * @returns {object} { {number} observerId, {number} status, {string} errortxt }
         */
        addObserver(
            textList: number | string,
            text: number | string,
            callback: (textListIndex: number, textIndex: number, text: string, language: number) => void
        ): { observerId: number, status: number, errortxt: string }
        /**
         * Removes an observer from a text
         * 
         * @param {string} textList The name of the textlist
         * @param {string} text The aliasname of the text
         * @param {number} observerId The observerId obtained by addObserver
         * @returns {object} { {number} status, {string} errortxt }
         */
        removeObserver(
            textList: number | string,
            text: number | string,
            observerId: number
        ): { status: number, errortxt: string }
        /**
         * Bulk saves texts, modified with setText (persistInFile: false)
         * 
         * @returns {Promise}
         */
        savePersistedTexts(): Promise
        /**
         * Loads persisted texts
         * 
         * @param {boolean} [sendToAllClients=false] Send text to all clients
         * @returns {Promise}
         */
        loadPersistedTexts(sendToAllClients?: boolean): Promise
        /**
         * Deletes persisted texts files and revert to texts published by LVD
         * 
         * @param {boolean} [sendToAllClients=false] Send text to all clients
         * @param {number} [languageIndexParam=undefined] filter by languageIndex (undefined -> all languages)
         * @param {number|string} [textListParam=undefined] filter by textList (undefined -> all textLists)
         * @returns {Promise}
         */
        loadPersistedTextsDefault(sendToAllClients?: boolean, languageIndexParam?: number, textListParam?: number | string): Promise
        /**
         * Returns a text list name.
         * 
         * @param {number|string} textListParam 
         * @returns {string|undefined}
         */
        getTextListName(textListParam: number | string): string | undefined
        /**
         * Returns a text list index.
         * 
         * @param {number|string} textListParam 
         * @returns {number|undefined}
         */
        getTextListIndex(textListParam: number | string): number | undefined
        /**
         * Returns a text name.
         * 
         * @param {number|string} textListParam 
         * @param {number|string} textParam 
         * @returns {string|undefined}
         */
        getTextName(textListParam: number | string, textParam: number | string): string | undefined
        /**
         * Returns a text index.
         * 
         * @param {number|string} textListParam 
         * @param {number|string} textParam 
         * @returns {number|undefined}
         */
        getTextIndex(textListParam: number | string, textParam: number | string): number | undefined
        /**
         * Function to check if parameter object is a instanceof Language.
         * This function can be used without importing the type Language to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof Language, else false
         */
        instanceofLanguage(object: any): boolean
        /**
         * ONLY AVAILABLE IN DESIGN MODE.
         * 
         * Checks whether the object store update changed the text list of the passed text list name in the current project language.
         * If no text list name is passed, the method checks whether the object store update changed any text list.
         * @async
         * @param {object} data The payload of the object store update response.
         * @param {string} [textList=undefined] The name of the text list without language prefix to check.
         * @returns {Promise} A promise that is resolved with a {boolean}: True if the object store update was relevant to the passed text list name. False if not.
         */
        isTextListUpdate(data: object, textList?: string): Promise<boolean>
        /**
         * ONLY AVAILABLE IN DESIGN MODE.
         * 
         * Checks whether the object store update changed the language definition of the passed language code.
         * If no language code is passed, the method checks whether the object store update changed any language.
         * @param {object} data The payload of the object store update response.
         * @param {string} [languageCode=undefined] The language code to check.
         * @returns {boolean} Returns true if the object store update was relevant to the passed language code. False if not.
         */
        isLanguageUpdate(data: object, languageCode?: string): boolean
    }
}
