"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 TestScoper_1 = require("./TestScoper");
const DecoratedModelElement_1 = require("../DecoratedModelElement");
const mobx_1 = require("mobx");
class PiElementReferenceM extends DecoratedModelElement_1.MobxModelElementImpl {
    constructor(referredElement) {
        super();
        this._PI_name = "UNKNOWN";
        this._PI_referred = null;
        this.referred = referredElement;
    }
    set name(value) {
        this._PI_name = value;
        this._PI_referred = null;
    }
    get name() {
        if (!!this._PI_referred) {
            this._PI_name = this._PI_referred.name;
        }
        else {
            this._PI_referred = TestScoper_1.TestScoper.getInstance().getFromVisibleElements(this._PI_name);
        }
        return this._PI_name;
    }
    get referred() {
        if (!!this._PI_referred) {
            return this._PI_referred;
        }
        else {
            this._PI_referred = TestScoper_1.TestScoper.getInstance().getFromVisibleElements(this._PI_name);
        }
        return this._PI_referred;
    }
    set referred(referredElement) {
        if (!!referredElement) {
            this._PI_name = referredElement.name;
        }
        else {
            this._PI_name = "";
        }
        this._PI_referred = referredElement;
    }
    static createNamedReference(name, typeName) {
        const result = new PiElementReferenceM(null);
        result.name = name;
        result.typeName = typeName;
        return result;
    }
    static create(name, typeName) {
        const result = new PiElementReferenceM(null);
        if (typeof name === "string") {
            result.name = name;
        }
        else if (typeof name === "object") {
            result.referred = name;
        }
        result.typeName = typeName;
        return result;
    }
}
__decorate([
    mobx_1.observable,
    __metadata("design:type", String)
], PiElementReferenceM.prototype, "_PI_name", void 0);
__decorate([
    mobx_1.observable,
    __metadata("design:type", Object)
], PiElementReferenceM.prototype, "_PI_referred", void 0);
__decorate([
    mobx_1.computed,
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], PiElementReferenceM.prototype, "name", null);
__decorate([
    mobx_1.computed,
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], PiElementReferenceM.prototype, "referred", null);
exports.PiElementReferenceM = PiElementReferenceM;
//# sourceMappingURL=PiElementReferenceM.js.map