"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.CdmAttributeContext = void 0;
const internal_1 = require("../internal");
class CdmAttributeContext extends internal_1.CdmObjectDefinitionBase {
    constructor(ctx, name) {
        super(ctx);
        this.TAG = CdmAttributeContext.name;
        // let bodyCode = () =>
        {
            this.objectType = internal_1.cdmObjectType.attributeContextDef;
            this.name = name;
            // For attribute context we don't follow standard path calculation behavior
            // this will get overwritten when parent set
            this.atCorpusPath = name;
            this.contents = new internal_1.CdmCollection(ctx, this, internal_1.cdmObjectType.attributeRef);
        }
        // return p.measure(bodyCode);
    }
    get atCorpusPath() {
        return this._atCorpusPath;
    }
    set atCorpusPath(val) {
        this._atCorpusPath = val;
    }
    static get objectType() {
        return internal_1.cdmObjectType.attributeContextDef;
    }
    /**
     * @internal
     */
    static createChildUnder(resOpt, acp) {
        // let bodyCode = () =>
        {
            if (!acp) {
                return undefined;
            }
            if (acp.type === internal_1.cdmAttributeContextType.passThrough) {
                return acp.under;
            }
            // this flag makes sure we hold on to any resolved object refs when things get copied
            resOpt.saveResolutionsOnCopy = true;
            let definition;
            let rtsApplied;
            // get a simple reference to definition object to avoid getting the traits that might be part of this ref
            // included in the link to the definition.
            if (acp.regarding) {
                // make a portable reference. this MUST be fixed up when the context node lands in the final document
                definition = acp.regarding.createPortableReference(resOpt);
                // now get the traits applied at this reference (applied only, not the ones that are part of the definition of the object)
                // and make them the traits for this context
                if (acp.includeTraits) {
                    rtsApplied = acp.regarding.fetchResolvedTraits(resOpt);
                }
            }
            const underChild = acp.under.ctx.corpus.MakeObject(internal_1.cdmObjectType.attributeContextDef, acp.name);
            // need context to make this a 'live' object
            underChild.ctx = acp.under.ctx;
            underChild.inDocument = acp.under.inDocument;
            underChild.type = acp.type;
            underChild.definition = definition;
            // add traits if there are any
            if (rtsApplied && rtsApplied.set) {
                rtsApplied.set.forEach((rt) => {
                    const traitRef = internal_1.CdmObjectBase.resolvedTraitToTraitRef(resOpt, rt);
                    underChild.exhibitsTraits.push(traitRef, typeof (traitRef) === 'string');
                });
            }
            // add to parent
            underChild.setParent(resOpt, acp.under);
            if (resOpt.mapOldCtxToNewCtx) {
                resOpt.mapOldCtxToNewCtx.set(underChild, underChild); // so we can find every node, not only the replaced ones
            }
            return underChild;
        }
        // return p.measure(bodyCode);
    }
    getObjectType() {
        // let bodyCode = () =>
        {
            return internal_1.cdmObjectType.attributeContextDef;
        }
        // return p.measure(bodyCode);
    }
    copyNode(resOpt) {
        // let bodyCode = () =>
        {
            // instead of copying the entire context tree, just the current node
            const copy = new CdmAttributeContext(this.ctx, this.name);
            copy.type = this.type;
            copy.inDocument = resOpt.wrtDoc;
            if (this.parent) {
                copy.parent = new internal_1.CdmAttributeContextReference(this.ctx, undefined);
                copy.parent.explicitReference = this.parent.explicitReference; // yes, just take the old pointer, will fix all later
            }
            if (this.definition) {
                copy.definition = this.definition.copy(resOpt);
                copy.definition.owner = this.definition.owner;
            }
            // make space for content, but no copy, done by caller
            copy.contents = new internal_1.CdmCollection(this.ctx, copy, internal_1.cdmObjectType.attributeRef);
            if (this.lineage && this.lineage.length > 0) {
                // trying to not allocate lineage collection unless needed
                for (const child of this.lineage) {
                    copy.addLineage(child.explicitReference, false);
                }
            }
            if (resOpt.mapOldCtxToNewCtx) {
                resOpt.mapOldCtxToNewCtx.set(copy, copy); // so we can find every node, not only the replaced ones
            }
            this.copyDef(resOpt, copy);
            return copy;
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     * clears any existing lineage and sets it to the provided context reference (or a reference to the context object is one is given instead)
     */
    setLineage(objLineage) {
        this.lineage = new internal_1.CdmCollection(this.ctx, this, internal_1.cdmObjectType.attributeContextRef);
        return this.addLineage(objLineage);
    }
    /**
     * @internal
     * add to the lineage array the provided context reference (or a reference to the context object is one is given instead)
     */
    addLineage(objLineage, validate = true) {
        // sort out which is the ref and which is the object.
        // attCtxRef object are special in that they don't support an inline definition but they do hold a pointer to the
        // actual context object in the explicit reference member
        let refLineage;
        if (objLineage.objectType === internal_1.cdmObjectType.attributeContextRef) {
            refLineage = objLineage;
            objLineage = refLineage.explicitReference;
        }
        else if (objLineage.objectType === internal_1.cdmObjectType.attributeContextDef) {
            var acLin = objLineage;
            refLineage = this.ctx.corpus.MakeObject(internal_1.cdmObjectType.attributeContextRef, acLin.atCorpusPath, true);
            refLineage.explicitReference = acLin;
        }
        else {
            // programming error
            return undefined;
        }
        if (!this.lineage) {
            // not allocated by default
            this.lineage = new internal_1.CdmCollection(this.ctx, this, internal_1.cdmObjectType.attributeContextRef);
        }
        if (refLineage.explicitReference.ID === this.ID) {
            // why do that?
            return undefined;
        }
        this.lineage.push(refLineage);
        // debugging. get the parent of the context tree and validate that this node is in that tree
        // if (validate === true) {
        //     CdmAttributeContext trace = refLineage.explicitReference as CdmAttributeContext;
        //     while (trace.parent !== undefined) {
        //         trace = trace.parent.explicitReference as CdmAttributeContext;
        //     }
        //     trace.validateLineage(undefined);
        // }
        return refLineage;
    }
    static prepareOptionsForResolveAttributes(resOptSource) {
        const resOptCopy = resOptSource.copy();
        // use this whenever we need to keep references pointing at things that were already found. used when 'fixing' references by localizing to a new document
        resOptCopy.saveResolutionsOnCopy = true;
        // for debugging help
        // if (resOptCopy.mapOldCtxToNewCtx !== undefined) {
        //     return undefined;
        // }
        resOptCopy.mapOldCtxToNewCtx = new Map();
        return resOptCopy;
    }
    /**
     * @internal
     */
    static getUnderContextForCacheContext(resOpt, ctx, acpUsed) {
        // a new context node is needed for these attributes, 
        // this tree will go into the cache, so we hang it off a placeholder parent
        // when it is used from the cache (or now), then this placeholder parent is ignored and the things under it are
        // put into the 'receiving' tree
        if (acpUsed) {
            const acpCache = {
                under: acpUsed.under,
                type: acpUsed.type,
                name: acpUsed.name,
                regarding: acpUsed.regarding,
                includeTraits: acpUsed.includeTraits
            };
            const parentCtxForCache = new CdmAttributeContext(ctx, "cacheHolder");
            parentCtxForCache.type = internal_1.cdmAttributeContextType.passThrough;
            acpCache.under = parentCtxForCache;
            return CdmAttributeContext.createChildUnder(resOpt, acpCache);
        }
        return undefined;
    }
    /**
     * @internal
     */
    getUnderContextFromCacheContext(resOpt, acpUsed) {
        // tree is found in cache, need a replacement tree node to put the sub-tree into. this replacement
        // needs to be build from the acp of the destination tree
        if (acpUsed) {
            return CdmAttributeContext.createChildUnder(resOpt, acpUsed);
        }
        return undefined;
    }
    /**
     * @internal
     */
    associateTreeCopyWithAttributes(resOpt, ras) {
        // deep copy the tree. while doing this also collect a map from old attCtx to new equivalent
        // this is where the returned tree fits in
        const cachedCtx = ras.attributeContext;
        if (!cachedCtx.copyAttributeContextTree(resOpt, this)) {
            return false;
        }
        ras.attributeContext = this;
        // run over the resolved attributes in the copy and use the map to swap the old ctx for the new version
        const fixResolveAttributeCtx = (rasSub) => {
            for (const ra of rasSub.set) {
                ra.attCtx = resOpt.mapOldCtxToNewCtx.get(ra.attCtx);
                // the target for a resolved att can be a typeAttribute OR it can be another resolvedAttributeSet (meaning a group)
                if (ra.target instanceof internal_1.ResolvedAttributeSet) {
                    ra.target.attributeContext = ra.attCtx;
                    fixResolveAttributeCtx(ra.target);
                }
            }
        };
        fixResolveAttributeCtx(ras);
        // now fix any lineage references 
        const fixAttCtxNodeLineage = (ac, acParent) => {
            if (!ac) {
                return;
            }
            if (acParent && ac.parent && ac.parent.explicitReference) {
                ac.parent.explicitReference = acParent;
            }
            if (ac.lineage && ac.lineage.length > 0) {
                // fix lineage
                for (const lin of ac.lineage) {
                    if (lin.explicitReference) {
                        // swap the actual object for the one in the new tree
                        lin.explicitReference = resOpt.mapOldCtxToNewCtx.get(lin.explicitReference);
                    }
                }
            }
            if (!ac.contents || ac.contents.length === 0) {
                return;
            }
            // look at all children
            for (const subSub of ac.contents) {
                fixAttCtxNodeLineage(subSub, ac);
            }
        };
        fixAttCtxNodeLineage(this, undefined);
        return true;
    }
    /**
     * @internal
     */
    finalizeAttributeContext(resOpt, pathStart, docHome, docFrom, monikerForDocFrom, finished = false) {
        // run over the attCtx tree again and 'fix it' fix means replace the parent and lineage reference path strings with
        // final values from new home and set the inDocument and fix any references to definitions
        // keep track of the paths to documents for fixing symbol refs. expensive to compute
        const foundDocPaths = new Map();
        if (monikerForDocFrom) {
            monikerForDocFrom = `${monikerForDocFrom}/`;
        }
        // first step makes sure every node in the tree has a good path for itself and a good document
        // second pass uses the paths from nodes to fix references to other nodes
        const fixAttCtxNodePaths = (subItem, pathFrom) => {
            const ac = subItem;
            if (!ac) {
                return;
            }
            ac.inDocument = docHome;
            // fix up the reference to defintion. need to get path from this document to the 
            // add moniker if this is a reference
            if (ac.definition) {
                ac.definition.inDocument = docHome;
                if (ac.definition && ac.definition.namedReference) {
                    // need the real path to this thing from the explicitRef held in the portable reference
                    // the real path is {monikerFrom/}{path from 'from' document to document holding the explicit ref/{declaredPath of explicitRef}}
                    // if we have never looked up the path between docs, do that now
                    const docFromDef = ac.definition.portableReference.inDocument; // if all parts not set, this is a broken portal ref!
                    let pathBetweenDocs = foundDocPaths.get(docFromDef);
                    if (!pathBetweenDocs) {
                        pathBetweenDocs = docFrom.importPathToDoc(docFromDef);
                        if (!pathBetweenDocs) {
                            // hmm. hmm.
                            pathBetweenDocs = '';
                        }
                        foundDocPaths.set(docFrom, pathBetweenDocs);
                    }
                    ac.definition.localizePortableReference(`${monikerForDocFrom}${pathBetweenDocs}`);
                }
            }
            // doc of parent ref
            if (ac.parent) {
                ac.parent.inDocument = docHome;
            }
            // doc of lineage refs
            if (ac.lineage && ac.lineage.length > 0) {
                for (const lin of ac.lineage) {
                    lin.inDocument = docHome;
                }
            }
            const divider = (!ac.atCorpusPath || !pathFrom.endsWith('/')) ? '/' : '';
            ac.atCorpusPath = `${pathFrom}${divider}${ac.name}`;
            if (!ac.contents || ac.contents.length === 0) {
                return;
            }
            // look at all children
            for (const subSub of ac.contents) {
                if (subSub.objectType === internal_1.cdmObjectType.attributeContextDef) {
                    fixAttCtxNodePaths(subSub, ac.atCorpusPath);
                }
            }
        };
        fixAttCtxNodePaths(this, pathStart);
        // now fix any lineage and parent references 
        const fixAttCtxNodeLineage = (subItem) => {
            const ac = subItem;
            if (!ac) {
                return;
            }
            // for debugLineage, write id
            //ac.name = `${ac.name}(${ac.Id})`;
            // parent ref
            if (ac.parent && ac.parent.explicitReference) {
                ac.parent.namedReference = ac.parent.explicitReference.atCorpusPath;
                // for debugLineage, write id
                //ac.parent.namedReference = `${(ac.parent.explicitReference as CdmAttributeContext).atCorpusPath}(${ac.parent.explicitReference.id})`;
            }
            // fix lineage
            if (ac.lineage && ac.lineage.length > 0) {
                for (const lin of ac.lineage) {
                    if (lin.explicitReference) {
                        // use the new path as the ref
                        lin.namedReference = lin.explicitReference.atCorpusPath;
                        // for debugLineage, write id
                        //lin.namedReference = `${(lin.explicitReference as CdmAttributeContext).atCorpusPath}(${lin.explicitReference.id})`;
                    }
                }
            }
            if (!ac.contents || ac.contents.length === 0) {
                return;
            }
            // look at all children
            for (const subSub of ac.contents) {
                fixAttCtxNodeLineage(subSub);
            }
        };
        fixAttCtxNodeLineage(this);
        if (finished) {
            resOpt.saveResolutionsOnCopy = false;
            resOpt.mapOldCtxToNewCtx = undefined;
        }
        return true;
    }
    /**
     * @internal
     */
    collectContextFromAtts(rasSub, collected) {
        rasSub.set.forEach(ra => {
            const raCtx = ra.attCtx;
            collected.add(raCtx);
            // the target for a resolved att can be a TypeAttribute OR it can be another ResolvedAttributeSet (meaning a group)
            if (ra.target instanceof internal_1.ResolvedAttributeSet) {
                // a group
                this.collectContextFromAtts(ra.target, collected);
            }
        });
    }
    /**
     * @internal
     */
    pruneToScope(scopeSet) {
        // run over the whole tree and make a set of the nodes that should be saved for sure. This is anything NOT under a generated set 
        // (so base entity chains, entity attributes entity definitions)
        // for testing, don't delete this
        // const countNodes = (subItem) => {
        //    if (subItem instanceof CdmAttributeContext) {
        //        return 1;
        //    }
        //    const ac: CdmAttributeContext = subItem as CdmAttributeContext;
        //    if (ac.contents === undefined || ac.contents.length === 0) {
        //        return 1;
        //    }
        //    // look at all children
        //    let total: number = 0;
        //    for (const subSub of ac.contents) {
        //        total += countNodes(subSub);
        //    }
        //    return 1 + total;
        // };
        // console.log(`Pre Prune ${countNodes(this)}`);
        // so ... the change from the old behavior is to depend on the lineage pointers to save the attribute defs
        // in the 'structure' part of the tree that might matter. keep all of the other structure info and keep some 
        // special nodes (like the ones that have removed attributes) that won't get found from lineage trace but that are
        // needed to understand what took place in resolution
        const nodesToSave = new Set();
        // helper that save the passed node and anything up the parent chain 
        const saveParentNodes = (currNode) => {
            var _a;
            if (nodesToSave.has(currNode)) {
                return true;
            }
            nodesToSave.add(currNode);
            // get the parent 
            if ((_a = currNode.parent) === null || _a === void 0 ? void 0 : _a.explicitReference) {
                return saveParentNodes(currNode.parent.explicitReference);
            }
            return true;
        };
        // helper that saves the current node (and parents) plus anything in the lineage (with their parents)
        const saveLineageNodes = (currNode) => {
            if (!saveParentNodes(currNode)) {
                return false;
            }
            if (currNode.lineage && currNode.lineage.length > 0) {
                for (const lin of currNode.lineage) {
                    if (lin.explicitReference) {
                        if (!saveLineageNodes(lin.explicitReference)) {
                            return false;
                        }
                    }
                }
            }
            return true;
        };
        const saveStructureNodes = (subItem, inGenerated, inProjection, inRemove) => {
            if (!(subItem instanceof CdmAttributeContext)) {
                return true;
            }
            const ac = subItem;
            if (ac.type === internal_1.cdmAttributeContextType.generatedSet) {
                inGenerated = true; // special mode where we hate everything except the removed att notes
            }
            if (inGenerated && ac.type === internal_1.cdmAttributeContextType.operationExcludeAttributes) {
                inRemove = true; // triggers us to know what to do in the next code block.
            }
            let removedAttribute = false;
            if (ac.type === internal_1.cdmAttributeContextType.attributeDefinition) {
                // empty attribute nodes are descriptions of source attributes that may or may not be needed. lineage will sort it out.
                // the exception is for attribute descriptions under a remove attributes operation. they are gone from the resolved att set, so
                // no history would remain 
                if (inRemove) {
                    removedAttribute = true;
                }
                else if (!ac.contents || ac.contents.length === 0) {
                    return true;
                }
            }
            // this attribute was removed by a projection operation, but we want to keep the node to indicate what the operation did
            if (ac.type === internal_1.cdmAttributeContextType.attributeExcluded) {
                removedAttribute = true;
            }
            if (!inGenerated || removedAttribute) {
                // mark this as something worth saving, sometimes 
                // these get discovered at the leaf of a tree that we want to mostly ignore, so can cause a
                // discontinuity in the 'save' chains, so fix that
                saveLineageNodes(ac);
            }
            if (ac.type === internal_1.cdmAttributeContextType.projection) {
                inProjection = true; // track this so we can do the next thing ...
            }
            if (ac.type === internal_1.cdmAttributeContextType.entity && inProjection) {
                // this is far enough, the entity that is somewhere under a projection chain
                // things under this might get saved through lineage, but down to this point will get in for sure
                return true;
            }
            if (!ac.contents || ac.contents.length === 0) {
                return true;
            }
            // look at all children
            for (const subSub of ac.contents) {
                if (!saveStructureNodes(subSub, inGenerated, inProjection, inRemove)) {
                    return false;
                }
            }
            return true;
        };
        if (!saveStructureNodes(this, false, false, false)) {
            return false;
        }
        // next, look at the attCtx for every resolved attribute. follow the lineage chain and mark all of those nodes as ones to save
        // also mark any parents of those as savers
        // so, do that ^^^ for every primary context found earlier
        for (const primCtx of scopeSet) {
            if (!saveLineageNodes(primCtx)) {
                return false;
            }
        }
        // now the cleanup, we have a set of the nodes that should be saved
        // run over the tree and re-build the contents collection with only the things to save
        const cleanSubGroup = (subItem) => {
            if (subItem.objectType === internal_1.cdmObjectType.attributeRef) {
                return true; // not empty
            }
            const ac = subItem;
            if (!nodesToSave.has(ac)) {
                return false; // don't even look at content, this all goes away
            }
            if (ac.contents && ac.contents.length > 0) {
                // need to clean up the content array without triggering the code that fixes in document or paths
                const newContent = [];
                for (const sub of ac.contents) {
                    // true means keep this as a child
                    if (cleanSubGroup(sub)) {
                        newContent.push(sub);
                    }
                }
                // clear the old content and replace
                ac.contents.clear();
                ac.contents.allItems.push(...newContent);
            }
            return true;
        };
        cleanSubGroup(this);
        // console.log(`Post Prune ${countNodes(this)}`);
        return true;
    }
    /**
     * @internal
     */
    validateLineage(resOpt) {
        // run over the attCtx tree and validate that it is self consistent on lineage
        // collect all nodes in the tree
        const attCtxInTree = new Set();
        const collectAllNodes = (subItem) => {
            const ac = subItem;
            if (!ac) {
                return;
            }
            attCtxInTree.add(ac);
            if (!ac.contents || ac.contents.length === 0) {
                return;
            }
            // look at all children
            for (const subSub of ac.contents) {
                if (subSub.objectType === internal_1.cdmObjectType.attributeContextDef) {
                    collectAllNodes(subSub);
                }
            }
        };
        collectAllNodes(this);
        // now make sure every lineage ref is in that set
        const checkLineage = (subItem) => {
            const ac = subItem;
            if (!ac) {
                return true;
            }
            if (ac.lineage && ac.lineage.length > 0) {
                for (const lin of ac.lineage) {
                    if (!attCtxInTree.has(lin.explicitReference)) {
                        return false;
                    }
                    //if (!resOpt.mapOldCtxToNewCtx.has(lin.explicitReference as CdmAttributeContext)) {
                    //return false;
                    //}
                }
            }
            if (!ac.contents || ac.contents.length === 0) {
                return true;
            }
            // look at all children
            for (const subSub of ac.contents) {
                if (subSub.objectType === internal_1.cdmObjectType.attributeContextDef) {
                    if (!checkLineage(subSub)) {
                        return false;
                    }
                }
            }
            return true;
        };
        checkLineage(this);
        return true;
    }
    /**
     * @internal
     */
    copyAttributeContextTree(resOpt, newNode, attCtxSet) {
        // remember which node in the new tree replaces which node in the old tree
        // the caller MUST use this to replace the explicit references held in the lineage and parent reference objects
        // and to change the context node that any associated resolved attributes will be pointing at
        resOpt.mapOldCtxToNewCtx.set(this, newNode); // so we can see the replacement for a copied node
        // now copy the children
        for (const child of this.contents.allItems) {
            if (child instanceof CdmAttributeContext) {
                if (newNode) {
                    const newChild = child.copyNode(resOpt);
                    newNode.contents.allItems.push(newChild); // need to NOT trigger the collection fix up and parent code
                    child.copyAttributeContextTree(resOpt, newChild);
                }
            }
        }
        return newNode;
    }
    copy(resOpt, host) {
        if (!resOpt) {
            resOpt = new internal_1.resolveOptions(this, this.ctx.corpus.defaultResolutionDirectives);
        }
        let copy;
        if (!host) {
            copy = this.copyNode(resOpt);
        }
        else {
            copy = host;
            copy.ctx = this.ctx;
            copy.name = this.getName();
            copy.contents.clear();
        }
        if (this.parent) {
            copy.parent = this.parent.copy(resOpt);
        }
        if (this.contents && this.contents.length > 0) {
            for (const child of this.contents.allItems) {
                copy.contents.push(child.copy(resOpt));
            }
        }
        if (this.lineage) {
            // trying to not allocate lineage collection unless needed
            for (const child of this.lineage) {
                copy.addLineage(child.explicitReference.copy(resOpt));
            }
        }
        return copy;
    }
    validate() {
        const missingFields = [];
        if (!this.name) {
            missingFields.push('name');
        }
        if (this.type === undefined) {
            missingFields.push('type');
        }
        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() {
        // let bodyCode = () =>
        {
            return this.name;
        }
        // return p.measure(bodyCode);
    }
    visit(pathFrom, preChildren, postChildren) {
        // let bodyCode = () =>
        {
            const path = this.fetchDeclaredPath(pathFrom);
            if (preChildren && preChildren(this, path)) {
                return false;
            }
            if (this.parent) {
                if (this.parent.visit(`${path}/parent/`, preChildren, postChildren)) {
                    return true;
                }
            }
            if (this.definition) {
                if (this.definition.visit(`${path}/definition/`, preChildren, postChildren)) {
                    return true;
                }
            }
            if (this.contents) {
                if (internal_1.CdmObjectBase.visitArray(this.contents, `${path}/`, preChildren, postChildren)) {
                    return true;
                }
            }
            if (this.lineage) {
                if (internal_1.CdmObjectBase.visitArray(this.lineage, `${path}/lineage/`, 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(baseDef, resOpt) {
        // let bodyCode = () =>
        {
            return false;
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    constructResolvedTraits(rtsb, resOpt) {
        // let bodyCode = () =>
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    constructResolvedAttributes(resOpt, under) {
        // let bodyCode = () =>
        {
            return undefined;
        }
        // return p.measure(bodyCode);
    }
    /**
     * @internal
     */
    setParent(resOpt, parent) {
        // let bodyCode = () =>
        {
            // will need a working reference to this as the parent
            const parentRef = this.ctx.corpus.MakeObject(internal_1.cdmObjectType.attributeContextRef, parent.atCorpusPath, true);
            if (this.name) {
                this.atCorpusPath = `${parent.atCorpusPath}/${this.name}`;
            }
            parentRef.explicitReference = parent;
            // setting this will let the 'localize references' code trace from any document back to where the parent is defined
            parentRef.inDocument = parent.inDocument;
            const parentContents = parent.contents;
            parentContents.push(this);
            this.parent = parentRef;
        }
        // return p.measure(bodyCode);
    }
}
exports.CdmAttributeContext = CdmAttributeContext;
//# sourceMappingURL=CdmAttributeContext.js.map