"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CdmE2ERelationship = void 0;
const internal_1 = require("../internal");
class CdmE2ERelationship extends internal_1.CdmObjectDefinitionBase {
    constructor(ctx, name) {
        super(ctx);
        this.TAG = CdmE2ERelationship.name;
        this.name = name;
        this.objectType = internal_1.cdmObjectType.e2eRelationshipDef;
        this.lastFileModifiedTime = null;
        this.lastFileModifiedOldTime = null;
    }
    static get objectType() {
        return internal_1.cdmObjectType.e2eRelationshipDef;
    }
    getObjectType() {
        return internal_1.cdmObjectType.e2eRelationshipDef;
    }
    copy(resOpt, host) {
        if (!resOpt) {
            resOpt = new internal_1.resolveOptions(this, this.ctx.corpus.defaultResolutionDirectives);
        }
        let copy;
        if (!host) {
            copy = new CdmE2ERelationship(this.ctx, this.name);
        }
        else {
            copy = host;
            copy.name = this.name;
        }
        copy.fromEntity = this.fromEntity;
        copy.fromEntityAttribute = this.fromEntityAttribute;
        copy.toEntity = this.toEntity;
        copy.toEntityAttribute = this.toEntityAttribute;
        this.copyDef(resOpt, copy);
        return copy;
    }
    validate() {
        const missingFields = [];
        if (!this.fromEntity) {
            missingFields.push('fromEntity');
        }
        if (!this.fromEntityAttribute) {
            missingFields.push('fromEntityAttribute');
        }
        if (!this.toEntity) {
            missingFields.push('toEntity');
        }
        if (!this.toEntityAttribute) {
            missingFields.push('toEntityAttribute');
        }
        if (missingFields.length > 0) {
            internal_1.Logger.error(this.ctx, this.TAG, this.validate.name, this.atCorpusPath, internal_1.cdmLogCode.ErrValdnIntegrityCheckFailure, this.atCorpusPath, missingFields.map((s) => `'${s}'`).join(', '));
            return false;
        }
        return true;
    }
    getName() {
        return this.name;
    }
    visit(pathFrom, preChildren, postChildren) {
        const path = this.fetchDeclaredPath(pathFrom);
        if (preChildren && preChildren(this, path)) {
            return false;
        }
        if (this.visitDef(path, preChildren, postChildren)) {
            return true;
        }
        if (postChildren && postChildren(this, path)) {
            return true;
        }
        return false;
    }
    isDerivedFrom(base, resOpt) {
        return false;
    }
    setLastFileModifiedTime(value) {
        this.setLastFileModifiedOldTime(this.lastFileModifiedTime);
        this.lastFileModifiedTime = value;
    }
    getlastFileModifiedTime() {
        return this.lastFileModifiedTime;
    }
    setLastFileModifiedOldTime(value) {
        this.lastFileModifiedOldTime = value;
    }
    getlastFileModifiedOldTime() {
        return this.lastFileModifiedOldTime;
    }
    resetLastFileModifiedOldTime() {
        this.setLastFileModifiedOldTime(null);
    }
    createCacheKey() {
        let nameAndPipe = '';
        if (this.name) {
            nameAndPipe = `${this.name}|`;
        }
        return `${nameAndPipe}${this.toEntity}|${this.toEntityAttribute}|${this.fromEntity}|${this.fromEntityAttribute}`;
    }
    ;
}
exports.CdmE2ERelationship = CdmE2ERelationship;
//# sourceMappingURL=CdmE2ERelationship.js.map