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

declare namespace SigApi {
    interface ApiViewModel extends ApiBase {
        /**
         * Finds a ViewModel by its instanceId
         * 
         * @param {string} instanceId The instanceId of the target
         * 
         * @returns {ViewModel|null} The ViewModel of that instanceId or null
         */
        getVmById(instanceId: string): ViewModel | null
        /**
         * Finds a ViewModel by its name. If a active CompositeControl is found in the childlist of the parent,
         * the element is searched in the childlist of that CompositeControl
         * 
         * @param {string} name The name of the target
         * @param {ViewModel} [parent=appViewModel] The startpoint of the search if undefined, the appVm is the parent
         * 
         * @returns {ViewModel|null} The ViewModel with that name in the given parent or null
         */
        getVmByName(name: string, parent?: ViewModel): ViewModel | null
        /**
         * This function will dynamically append a new composite control property to the given parent viewmodel.
         * After success, you may use "sigApi.properties.getProperty(parentVm.getInstanceId(), slotName)" to obtain the property or
         * use "sigApi.vm.removeCC(parentVm, slotName) to remove the property.
         * For static overload (overload at creation) use the staticOvDpId parameter (minimal performance impact).
         * For dynamic overload (overload after creation) use the "Property.overload()" api after obtaining the property (higher performance impact).
         * 
         * @param {ViewModel} parentVM The parent viewmodel where the new composite control property should be added
         * @param {string} ccName The name of the composite control which should be rendered
         * @param {string} slotName The name of the slot in which the composite control should be rendered (also used as name for the composite control property)
         * @param {number|string} [staticOvDpId=null] The id or the name of the datapoint for the static overload, or null if no static overload should be done
         * @param {boolean} [deferedUse=false] If set to true the new CC is not setActive automatically and has style class sig-element-no-render (display: none) applied
         * @param {DocumentFragment} [documentFragment] A documentFragment to append to instead of parentVM domRef
         * @returns {boolean} true if the composite control property was added successfully and false if it was not
         */
        appendNewCC(
            parent: ViewModel,
            ccName: string,
            slotName: string,
            staticOvDpId?: number | string,
            deferedUse?: boolean,
            documentFragment?: DocumentFragment
        ): boolean
        /**
         * This function will dynamically append a new composite control scheme property to the given parent viewmodel.
         * After success, you may use "sigApi.properties.getProperty(parentVm.getInstanceId(), slotName)" to obtain the property or
         * use "sigApi.vm.removeCC(parentVm, slotName) to remove the property.
         * For static overload (overload at creation) use the staticOvDpId parameter (minimal performance impact).
         * For dynamic overload (overload after creation) use the "Property.overload()" api after obtaining the property (higher performance impact).
         * Be aware that a composite control scheme property is asynchronous and can change its state at all times due to datapoint evaluation/change.
         * Consider obtaining the property and use "Property.addObserver()" api to get notified on changes.
         * 
         * @param {ViewModel} parent The parent viewmodel where the new composite control scheme property should be added
         * @param {string} schemeName The name of the composite control scheme which should be added
         * @param {string|number} schemeInputDpId The id or the name of the input datapoint for the composite control scheme (if a number with a 'c' at the end is given, that number is used as constant input e.g. '12c')
         * @param {string} slotName The name of the slot in which the active composite control should be rendered (also used as name for the composite control scheme property)
         * @param {string} [defaultCCName=undefined] The name of the composite control which should be used if no scheme entry is active. If null/undefined is given, then there will be no default
         * @param {number|string} [staticOvDpId=null] The id or the name of the datapoint for the static overload, or null if no static overload should be done
         * @returns {boolean} true if the composite control scheme property was added successfully and false if it was not
         */
        appendNewCCScheme(
            parent: ViewModel,
            schemeName: string,
            schemeInputDpId: number | string,
            slotName: string,
            defaultCCName?: string,
            staticOvDpId?: number | string
        ): boolean
        /**
         * This function will dynamically remove the given composite control (scheme) property from the parent viewmodel
         * 
         * @param {ViewModel} parentVM The viewmodel from which the composite control (scheme) property should be removed
         * @param {string} slotName The name of the slot where the composite control is rendered (also used as name for the composite control (scheme) property)
         * @returns {boolean} true if the composite control (scheme) property was removed successfully or false if it was not
         */
        removeCC(parentVM: ViewModel, slotName: string): boolean
        /**
         * Returns detail information about state property value.
         * 
         * The state property value is a merged value depending on
         *  * state/stateScheme
         *  * access (accessNumber) of the control
         *  * writeProtected flag of the dataPoint
         *  * access (accessNumber) of the dataPoint
         * @param {string} instanceId 
         * @returns {StatePropertyDetailInfo[]}
         */
        getStatePropertyDetailInfo(
            instanceId: string
        ): StatePropertyDetailInfo[]
        /**
         * Registers a callback which is executed when the element is rendered (-> height && width != 0)
         * 
         * @param {HTMLElement} element The Element which should be observed
         * @param {Function} callback The Function that should be executed if the element is ready
         * @param {Function} [errorCallback] The Function that is executed if the element is not rendered in the given time
         * @param {number} [delay=20] The maximum waiting time in render cycles.
         * @returns {boolean} Returns true if the callback was successfully added, otherwise false.
         */
        addRenderCallback(
            element: HTMLElement,
            callback: Function,
            errorCallback?: Function,
            delay?: number
        ): boolean
        /**
         * Creates a new ViewModel instance. ViewModels created by this function must be destroyed by calling {@link ViewModel}.destroy(...) with parameter destroyVmInstance: true.
         * 
         * WARNING: This api function is exposing low level runtime features (for experienced users only).
         * @param {ViewModelBlueprint} vmBlueprint 
         * @returns {ViewModel}
         */
        newViewModel(vmBlueprint: ViewModelBlueprint): ViewModel
        /**
         * Function to check if parameter object is a instanceof ViewModel.
         * This function can be used without importing the type ViewModel to be used with the instanceof operator.
         * @param {*} object Any object to type check
         * @returns {boolean} Returns true if parameter object is instanceof ViewModel, else false
         */
        instanceofViewModel(object: any): boolean
    }
}
