"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.ProjectionDirective = void 0;
const internal_1 = require("../../internal");
/**
 * Directives to pass to the top level projection on resolution
 * ProjectionDirective contains all the inputs for a projection towards resolution.
 * ProjectionContext is the context that initializes, lives and evolves through the projection resolution process.
 * ProjectionContext contains an instance of ProjectionDirective.
 * @internal
 */
// tslint:disable:variable-name
class ProjectionDirective {
    constructor(resOpt, owner, ownerRef = null) {
        var _a, _b, _c, _d, _e, _f;
        this.resOpt = resOpt;
        // Owner information
        this.owner = owner;
        this.ownerRef = ownerRef;
        if ((owner === null || owner === void 0 ? void 0 : owner.objectType) === internal_1.cdmObjectType.entityAttributeDef) {
            // Entity Attribute
            const _owner = owner;
            this.cardinality = _owner.cardinality ? _owner.cardinality : new internal_1.CardinalitySettings(_owner);
            this.isSourcePolymorphic = (_owner.isPolymorphicSource !== undefined && _owner.isPolymorphicSource !== null && _owner.isPolymorphicSource === true);
        }
        else {
            // Entity Def pr Type Attribute
            this.cardinality = undefined;
            this.isSourcePolymorphic = false;
        }
        this.isReferenceOnly = (((_a = resOpt.directives) === null || _a === void 0 ? void 0 : _a.has('referenceOnly')) === true);
        this.isNormalized = (((_b = resOpt.directives) === null || _b === void 0 ? void 0 : _b.has('normalized')) === true);
        this.isStructured = (((_c = resOpt.directives) === null || _c === void 0 ? void 0 : _c.has('structured')) === true);
        this.isVirtual = (((_d = resOpt.directives) === null || _d === void 0 ? void 0 : _d.has('virtual')) === true);
        this.hasNoMaximumDepth = (((_e = resOpt.directives) === null || _e === void 0 ? void 0 : _e.has('noMaxDepth')) === true);
        this.isArray = (((_f = resOpt.directives) === null || _f === void 0 ? void 0 : _f.has('isArray')) === true);
        // if noMaxDepth directive the max depth is 32 else defaults to what was set by the user
        // these depths were arbitrary and were set for the resolution guidance
        // re-using the same for projections as well
        this.maximumDepth = this.hasNoMaximumDepth ? internal_1.DepthInfo.maxDepthLimit : resOpt.maxDepth;
    }
    /**
     * The entity/type attribute name or "{a/A}"
     * This may pass through at each operation action/transformation
     * @internal
     */
    get originalSourceAttributeName() {
        var _a, _b;
        return (((_a = this.owner) === null || _a === void 0 ? void 0 : _a.objectType) === internal_1.cdmObjectType.entityAttributeDef || ((_b = this.owner) === null || _b === void 0 ? void 0 : _b.objectType) === internal_1.cdmObjectType.typeAttributeDef) ? this.owner.getName() : undefined;
    }
}
exports.ProjectionDirective = ProjectionDirective;
//# sourceMappingURL=ProjectionDirective.js.map