export class Report {

    //===================================
    // PUBLIC METHODS
    //===================================

    toggleValue(name, value1, value2, refresh) {
        reportObject.getContextValue(name) === value1 ?
            reportObject.setContextValue(name, value2) :
            reportObject.setContextValue(name, value1);
        if (refresh === true) this.refresh();
    }

    setValue(name, value, refresh) {
        reportObject.setContextValue(name, value);
        if (refresh === true) this.refresh();
    }

    getValue(name, defaultValue) {
        return reportObject.getContextValue(name) ?? defaultValue;
    }

    clearValue(name, refresh) {
        reportObject.removeContextValue(name);
        if (refresh === true) this.refresh();
    }

    clearAllValues(refresh) {
        reportObject.clearValue();
        if (refresh === true) this.refresh();
    }

    print() {
        // call global report object print function passed down by report element
        reportObject.print();
    }

    refresh() {
        // call global report object refresh function passed down by report element
        reportObject.refresh();
    }

    execute(scriptName, values, success) {

        reportObject.executeRuleScript({
            name: scriptName,
            context: { values: values },
            success: (e) => {
                if (success) {
                    success(e);
                }
                else {
                    this.refresh();
                }
            }
        });

    }

}

window["Report"] = new Report();