"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressionTester = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const ExpressionConfiguration_1 = require("@appglue/common/dist/Expressions/ExpressionConfiguration");
const GreaterThan_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/GreaterThan");
const IfThenExpression_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/IfThenExpression");
const MultiplyExpression_1 = require("@appglue/common/dist/Expressions/Expressions/Math/MultiplyExpression");
const StringLengthExpression_1 = require("@appglue/common/dist/Expressions/Expressions/String/StringLengthExpression");
const DataDefinition_1 = require("@appglue/common/dist/Common/Data/DataDefinition");
const BooleanDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/BooleanDataDefinition");
const NumberDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/NumberDataDefinition");
const ObjectDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/ObjectDataDefinition");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const LessThanExpression_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/LessThanExpression");
const XExecutableTester_1 = require("../XExecutableTester");
const LogicData_1 = require("../../../Expressions/Testing/LogicData");
const StoryData_1 = require("../../StoryBook/StoryData");
const OrGroup_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/OrGroup");
function getIfThenExpression() {
    let exp = new ExpressionConfiguration_1.ExpressionConfiguration();
    let baseExpression = new IfThenExpression_1.IfThenExpression();
    baseExpression.ifThenStyle = IfThenExpression_1.IfThenStyle.BRANCH_DATA_RETURN;
    baseExpression.showElseAsDefault = true;
    baseExpression.ifBranches[0].ifExpression.elements[0].variableName = "isEmployee";
    let subExpression = new MultiplyExpression_1.MultiplyExpression();
    subExpression.value2.value = 10;
    subExpression.value1.variableName = "income";
    baseExpression.ifBranches[0].thenExpression.subExpression = subExpression;
    let greaterThan = new GreaterThan_1.GreaterThanExpression();
    let strLen = new StringLengthExpression_1.StringLengthExpression();
    strLen.value1.variableName = "person.name";
    greaterThan.value1.subExpression = strLen;
    greaterThan.value2.value = 5;
    let secondIf = baseExpression.addIfBranch();
    secondIf.ifExpression = new OrGroup_1.OrGroup();
    secondIf.ifExpression.elements[0].subExpression = greaterThan;
    let lessThan = new LessThanExpression_1.LessThanExpression();
    lessThan.value1.variableName = "age";
    lessThan.value2.value = 40;
    secondIf.ifExpression.add();
    secondIf.ifExpression.elements[1].subExpression = lessThan;
    secondIf.thenExpression.value = 1000;
    baseExpression.defaultOutput.value = 0;
    exp.expression = baseExpression;
    return exp;
}
let datadef = new DataDefinition_1.DataDefinition();
datadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isEmployee"));
datadef.fields.push(new NumberDataDefinition_1.NumberDataDefinition("income"));
datadef.fields.push(new NumberDataDefinition_1.NumberDataDefinition("age"));
datadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isContractor"));
let personfield = new ObjectDataDefinition_1.ObjectDataDefinition("person");
personfield.fields.push(new StringDataDefinition_1.StringDataDefinition("name"));
datadef.fields.push(personfield);
exports.ExpressionTester = [
    new StoryData_1.StoryNode(() => {
        let expression = getIfThenExpression();
        expression.inputData = datadef;
        expression.executionResult = () => new NumberDataDefinition_1.NumberDataDefinition();
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: expression });
    }, "Test UI", "Expression", "Default Return"),
    new StoryData_1.StoryNode(() => {
        function getLogicExpressionResultElseIfAtEnd() {
            let exp = new ExpressionConfiguration_1.ExpressionConfiguration();
            exp.executionResult = new NumberDataDefinition_1.NumberDataDefinition();
            let baseExpression = new IfThenExpression_1.IfThenExpression();
            baseExpression.ifThenStyle = IfThenExpression_1.IfThenStyle.DATA_RETURN;
            baseExpression.ifBranches[0].ifExpression.elements[0].variableName = "isEmployee";
            let greaterThan = new GreaterThan_1.GreaterThanExpression();
            let strLen = new StringLengthExpression_1.StringLengthExpression();
            strLen.value1.variableName = "person.name";
            greaterThan.value1.subExpression = strLen;
            greaterThan.value2.value = 5;
            let secondIf = baseExpression.addIfBranch();
            secondIf.ifExpression.elements[0].subExpression = greaterThan;
            secondIf.thenExpression.value = 20;
            // true result
            let subExpression = new MultiplyExpression_1.MultiplyExpression();
            subExpression.value2.value = 10;
            subExpression.value1.variableName = "income";
            baseExpression.trueOutput.subExpression = subExpression;
            // false result
            baseExpression.defaultOutput.variableName = "income";
            exp.expression = baseExpression;
            exp.executionResult = () => new NumberDataDefinition_1.NumberDataDefinition();
            return exp;
        }
        let expression = getLogicExpressionResultElseIfAtEnd();
        expression.inputData = datadef;
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: expression });
    }, "Test UI", "Expression", "Data Return"),
    new StoryData_1.StoryNode(() => {
        let expression = (0, LogicData_1.getIfElseSimpleRule)();
        expression.inputData = datadef;
        expression.executionResult = () => new NumberDataDefinition_1.NumberDataDefinition();
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: expression });
    }, "Test UI", "Expression", "Logic Return"),
];
//# sourceMappingURL=XExecutableTester.Expression-stories.js.map