"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.CdmPurposeDefinition = void 0;
const internal_1 = require("../internal");
class CdmPurposeDefinition extends internal_1.CdmObjectDefinitionBase {
    constructor(ctx, purposeName, extendsPurpose) {
        super(ctx);
        this.TAG = CdmPurposeDefinition.name;
        // let bodyCode = () =>
        {
            this.objectType = internal_1.cdmObjectType.purposeDef;
            this.purposeName = purposeName;
            if (extendsPurpose) {
                this.extendsPurpose = extendsPurpose;
            }
        }
        // return p.measure(bodyCode);
    }
    static get objectType() {
        return internal_1.cdmObjectType.purposeDef;
    }
    getObjectType() {
        // let bodyCode = () =>
        {
            return internal_1.cdmObjectType.purposeDef;
        }
        // return p.measure(bodyCode);
    }
    copy(resOpt, host) {
        // let bodyCode = () =>
        {
            if (!resOpt) {
                resOpt = new internal_1.resolveOptions(this, this.ctx.corpus.defaultResolutionDirectives);
            }
            let copy;
            if (!host) {
                copy = new CdmPurposeDefinition(this.ctx, this.purposeName, undefined);
            }
            else {
                copy = host;
                copy.purposeName = this.purposeName;
            }
            copy.extendsPurpose = this.extendsPurpose
                ? this.extendsPurpose.copy(resOpt)
                : undefined;
            this.copyDef(resOpt, copy);
            return copy;
        }
        // return p.measure(bodyCode);
    }
    validate() {
        if (!this.purposeName) {
            let missingFields = ['purposeName'];
            internal_1.Logger.error(this.ctx, this.TAG, this.validate.name, this.atCorpusPath, internal_1.cdmLogCode.ErrValdnIntegrityCheckFailure, missingFields.map((s) => `'${s}'`).join(', '), this.atCorpusPath);
            return false;
        }
        return true;
    }
    getName() {
        // let bodyCode = () =>
        {
            return this.purposeName;
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    extendsPurposeRef() {
        // let bodyCode = () =>
        {
            return this.extendsPurpose;
        }
        // return p.measure(bodyCode);
    }
    visit(pathFrom, preChildren, postChildren) {
        // let bodyCode = () =>
        {
            const path = this.fetchDeclaredPath(pathFrom);
            if (preChildren && preChildren(this, path)) {
                return false;
            }
            if (this.extendsPurpose) {
                this.extendsPurpose.owner = this;
                if (this.extendsPurpose.visit(`${path}/extendsPurpose/`, preChildren, postChildren)) {
                    return true;
                }
            }
            if (this.visitDef(path, preChildren, postChildren)) {
                return true;
            }
            if (postChildren && postChildren(this, path)) {
                return true;
            }
            return false;
        }
        // return p.measure(bodyCode);
    }
    isDerivedFrom(base, resOpt) {
        // let bodyCode = () =>
        {
            if (!resOpt) {
                resOpt = new internal_1.resolveOptions(this, this.ctx.corpus.defaultResolutionDirectives);
            }
            return this.isDerivedFromDef(resOpt, this.extendsPurposeRef(), this.getName(), base);
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    constructResolvedTraits(rtsb, resOpt) {
        // let bodyCode = () =>
        {
            this.constructResolvedTraitsDef(this.extendsPurposeRef(), rtsb, resOpt);
            // rtsb.cleanUp();
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    constructResolvedAttributes(resOpt, under) {
        // let bodyCode = () =>
        {
            return undefined;
        }
        // return p.measure(bodyCode);
    }
}
exports.CdmPurposeDefinition = CdmPurposeDefinition;
//# sourceMappingURL=CdmPurposeDefinition.js.map