"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.resolveOptions = void 0;
const internal_1 = require("../internal");
class resolveOptions {
    constructor(parameter, directives) {
        this.importsLoadStrategy = internal_1.importsLoadStrategy.lazyLoad; // defines at which point the Object Model will try to load the imported documents.
        this.resolvedAttributeLimit = 4000; // the limit for the number of resolved attributes allowed per entity. if the number is exceeded, the resolution will fail
        this.maxOrdinalForArrayExpansion = 20; // the maximum value for the end ordinal in an ArrayExpansion operation
        this.maxDepth = 2; // the maximum depth that entity attributes will be resolved before giving up
        /**
         * Indicates if resolution guidance was used at any point during resolution
         * @internal
         */
        this.usedResolutionGuidance = false;
        this.symbolRefSet = new internal_1.SymbolSet();
        this.depthInfo = new internal_1.DepthInfo();
        this.inCircularReference = false;
        this.currentlyResolvingEntities = new Set();
        this.wrtDoc = this.fetchDocument(parameter);
        // provided or default to 'avoid one to many relationship nesting and to use foreign keys for many to one refs'.
        // this is for back compat with behavior before the corpus has a default directive property
        if (directives) {
            this.directives = directives.copy();
        }
        else {
            const directivesSet = new Set();
            directivesSet.add('normalized');
            directivesSet.add('referenceOnly');
            this.directives = new internal_1.AttributeResolutionDirectiveSet(directivesSet);
        }
    }
    /**
     * @deprecated please use importsLoadStrategy instead.
     * when enabled, all the imports will be loaded and the references checked otherwise will be delayed until the symbols are required.
     */
    get strictValidation() {
        if (this.importsLoadStrategy === internal_1.importsLoadStrategy.lazyLoad) {
            return undefined;
        }
        return this.importsLoadStrategy === internal_1.importsLoadStrategy.load;
    }
    /**
     * @deprecated please use importsLoadStrategy instead.
     * when enabled, all the imports will be loaded and the references checked otherwise will be delayed until the symbols are required.
     */
    set strictValidation(strictValidation) {
        if (strictValidation === undefined) {
            this.importsLoadStrategy = internal_1.importsLoadStrategy.lazyLoad;
        }
        else if (strictValidation) {
            this.importsLoadStrategy = internal_1.importsLoadStrategy.load;
        }
        else {
            this.importsLoadStrategy = internal_1.importsLoadStrategy.doNotLoad;
        }
    }
    /**
     * @internal
     */
    checkAttributeCount(amount) {
        if (this.resolvedAttributeLimit !== undefined) {
            if (amount > this.resolvedAttributeLimit) {
                return false;
            }
        }
        return true;
    }
    /**
     * @internal
     * Creates a copy of the resolve options object
     */
    copy() {
        const resOptCopy = new resolveOptions();
        resOptCopy.wrtDoc = this.wrtDoc;
        if (this.depthInfo) {
            resOptCopy.depthInfo = this.depthInfo.copy();
        }
        if (this.directives) {
            resOptCopy.directives = this.directives.copy();
        }
        resOptCopy.depthInfo = this.depthInfo.copy();
        resOptCopy.inCircularReference = this.inCircularReference;
        resOptCopy.localizeReferencesFor = this.localizeReferencesFor;
        resOptCopy.indexingDoc = this.indexingDoc;
        resOptCopy.shallowValidation = this.shallowValidation;
        resOptCopy.resolvedAttributeLimit = this.resolvedAttributeLimit;
        resOptCopy.mapOldCtxToNewCtx = this.mapOldCtxToNewCtx; // ok to share this map
        resOptCopy.importsLoadStrategy = this.importsLoadStrategy;
        resOptCopy.saveResolutionsOnCopy = this.saveResolutionsOnCopy;
        resOptCopy.currentlyResolvingEntities = this.currentlyResolvingEntities; // ok to share this map
        resOptCopy.usedResolutionGuidance = this.usedResolutionGuidance;
        return resOptCopy;
    }
    /**
     * Fetches the document that contains the owner of the CdmObject.
     */
    fetchDocument(obj) {
        var _a;
        if (!obj) {
            return undefined;
        }
        if (obj instanceof internal_1.CdmDocumentDefinition) {
            return obj;
        }
        if (obj.inDocument) {
            return obj.inDocument;
        }
        return (_a = obj.owner) === null || _a === void 0 ? void 0 : _a.inDocument;
    }
}
exports.resolveOptions = resolveOptions;
//# sourceMappingURL=resolveOptions.js.map