"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const mobx_1 = require("mobx");
const testmodel_1 = require("../testmodel");
const CoreTestModel_1 = require("../testmodel/CoreTestModel");
const CoreTestEntity_1 = require("../testmodel/domain/CoreTestEntity");
const CoreTestAttribute_1 = require("../testmodel/domain/CoreTestAttribute");
const CoreTestFunction_1 = require("../testmodel/domain/CoreTestFunction");
const CoreTestVariable_1 = require("../testmodel/domain/CoreTestVariable");
require("./CoreTestExpression");
class CoreTestContext {
    constructor(initialExpression) {
        this.model = CoreTestModel_1.CoreTestModel.create("CoreTestModel");
        this.initialize();
        this.rootElement = initialExpression ? initialExpression : this.model;
    }
    set rootElement(exp) {
        this._rootElement = exp;
        this._rootElement.container = null;
        exp.container = this;
        exp.propertyIndex = undefined;
        exp.propertyName = "rootElement";
    }
    get rootElement() {
        return this._rootElement;
    }
    toString() {
        return "CoreTestContext";
    }
    initialize() {
        const unit = testmodel_1.CoreTestUnit.create("CoreTestUnit");
        this.model.units.push(unit);
        const entity1 = CoreTestEntity_1.CoreTestEntity.create("Person");
        const attribute1 = CoreTestAttribute_1.CoreTestAttribute.create("name");
        const attribute2 = CoreTestAttribute_1.CoreTestAttribute.create("age");
        entity1.attributes.push(attribute1);
        entity1.attributes.push(attribute2);
        const entity2 = CoreTestEntity_1.CoreTestEntity.create("Company");
        const attribute21 = CoreTestAttribute_1.CoreTestAttribute.create("name");
        const attribute22 = CoreTestAttribute_1.CoreTestAttribute.create("VAT_Number");
        entity2.attributes.push(attribute21);
        entity2.attributes.push(attribute22);
        const f1 = CoreTestFunction_1.CoreTestFunction.create("length");
        const f2 = CoreTestFunction_1.CoreTestFunction.create("first");
        const f3 = CoreTestFunction_1.CoreTestFunction.create("last");
        const var1 = CoreTestVariable_1.CoreTestVariable.create("Variable1", entity1);
        const var2 = CoreTestVariable_1.CoreTestVariable.create("VariableNumber2", entity2);
        const var3 = CoreTestVariable_1.CoreTestVariable.create("Resultvar", entity1);
        const var4 = CoreTestVariable_1.CoreTestVariable.create("Param", entity1);
        unit.entities.push(entity1);
        unit.entities.push(entity2);
        entity1.functions.push(f1);
        entity1.functions.push(f2);
        entity2.functions.push(f3);
        f1.parameters.push(var1);
        f1.parameters.push(var2);
        f2.parameters.push(var3);
        f3.parameters.push(var4);
        f1.expression = this.getSampleExpression();
    }
    getSampleExpression() {
        const ifExpression = new testmodel_1.CoreTestIfExpression();
        const condition = testmodel_1.CoretestComparisonExpression.create("<");
        condition.left = testmodel_1.CoreTestNumberLiteralExpression.create("2");
        condition.right = testmodel_1.CoreTestNumberLiteralExpression.create("5");
        ifExpression.condition = condition;
        const thenExpression = new testmodel_1.CoreTestOrExpression();
        const leftOr = new testmodel_1.CoreTestOrExpression();
        const varRef = new testmodel_1.CoreTestVariableRefExpression();
        varRef.referredName = "Variable1";
        varRef.attribute = "Name";
        const equals = testmodel_1.CoretestComparisonExpression.create("=");
        equals.left = testmodel_1.CoreTestStringLiteralExpression.create("No");
        equals.right = varRef;
        leftOr.right = equals;
        leftOr.left = testmodel_1.CoreTestStringLiteralExpression.create("Yes");
        thenExpression.left = leftOr;
        const rightOr = new testmodel_1.CoreTestAndExpression();
        thenExpression.right = rightOr;
        const rightAnd = testmodel_1.CoretestComparisonExpression.create("<");
        rightAnd.left = testmodel_1.CoreTestNumberLiteralExpression.create("122");
        rightAnd.right = testmodel_1.CoreTestNumberLiteralExpression.create("42");
        const leftAnd = testmodel_1.CoretestComparisonExpression.create("<");
        leftAnd.left = testmodel_1.CoreTestStringLiteralExpression.create("Hello World");
        leftAnd.right = testmodel_1.CoreTestStringLiteralExpression.create("Hello Universe");
        rightOr.right = rightAnd;
        rightOr.left = leftAnd;
        ifExpression.thenExpression = thenExpression;
        const divideExpression = new testmodel_1.CoreTestPlusExpression();
        divideExpression.left = testmodel_1.CoreTestNumberLiteralExpression.create("1");
        divideExpression.right = testmodel_1.CoreTestNumberLiteralExpression.create("2");
        const multiplyExpression = new testmodel_1.CoreTestPlusExpression();
        multiplyExpression.left = divideExpression;
        multiplyExpression.right = null;
        const plusExpression = new testmodel_1.CoreTestPlusExpression();
        plusExpression.left = testmodel_1.CoreTestStringLiteralExpression.create("Maybe");
        plusExpression.right = multiplyExpression;
        ifExpression.elseExpression = plusExpression;
        return rightAnd;
        const s1 = testmodel_1.CoreTestStringLiteralExpression.create("Hello CoreTest");
        const s2 = testmodel_1.CoreTestStringLiteralExpression.create("Goodbye");
        const plus = new testmodel_1.CoreTestPlusExpression();
        plus.left = s1;
        plus.right = s2;
    }
}
__decorate([
    mobx_1.observable,
    __metadata("design:type", CoreTestModel_1.CoreTestModelElement)
], CoreTestContext.prototype, "_rootElement", void 0);
__decorate([
    mobx_1.action,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], CoreTestContext.prototype, "initialize", null);
exports.CoreTestContext = CoreTestContext;
//# sourceMappingURL=CoreTestContext.js.map