"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Entities
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityMetaData = exports.PropertyMetaData = exports.PrimitiveTypeCode = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const core_geometry_1 = require("@itwin/core-geometry");
const ElementProps_1 = require("./ElementProps");
/** The primitive types of an Entity property.
 * @beta
 */
var PrimitiveTypeCode;
(function (PrimitiveTypeCode) {
    PrimitiveTypeCode[PrimitiveTypeCode["Uninitialized"] = 0] = "Uninitialized";
    PrimitiveTypeCode[PrimitiveTypeCode["Binary"] = 257] = "Binary";
    PrimitiveTypeCode[PrimitiveTypeCode["Boolean"] = 513] = "Boolean";
    PrimitiveTypeCode[PrimitiveTypeCode["DateTime"] = 769] = "DateTime";
    PrimitiveTypeCode[PrimitiveTypeCode["Double"] = 1025] = "Double";
    PrimitiveTypeCode[PrimitiveTypeCode["Integer"] = 1281] = "Integer";
    PrimitiveTypeCode[PrimitiveTypeCode["Long"] = 1537] = "Long";
    PrimitiveTypeCode[PrimitiveTypeCode["Point2d"] = 1793] = "Point2d";
    PrimitiveTypeCode[PrimitiveTypeCode["Point3d"] = 2049] = "Point3d";
    PrimitiveTypeCode[PrimitiveTypeCode["String"] = 2305] = "String";
    PrimitiveTypeCode[PrimitiveTypeCode["IGeometry"] = 2561] = "IGeometry";
})(PrimitiveTypeCode || (exports.PrimitiveTypeCode = PrimitiveTypeCode = {}));
/** Metadata for a property.
 * @beta
 * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use the `Property` class from @itwin/ecschema-metadata` instead.
 */
// eslint-disable-next-line @typescript-eslint/no-deprecated
class PropertyMetaData {
    primitiveType;
    structName;
    extendedType;
    description;
    displayLabel;
    minimumValue;
    maximumValue;
    minimumLength;
    maximumLength;
    readOnly;
    kindOfQuantity;
    isCustomHandled;
    isCustomHandledOrphan;
    minOccurs;
    maxOccurs;
    direction;
    relationshipClass;
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    customAttributes;
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    constructor(jsonObj) {
        this.primitiveType = jsonObj.primitiveType;
        if (jsonObj.structName)
            this.structName = jsonObj.structName;
        this.extendedType = jsonObj.extendedType;
        this.description = jsonObj.description;
        this.displayLabel = jsonObj.displayLabel;
        if (undefined !== jsonObj.minimumValue)
            this.minimumValue = jsonObj.minimumValue;
        if (undefined !== jsonObj.maximumValue)
            this.maximumValue = jsonObj.maximumValue;
        if (undefined !== jsonObj.minimumLength)
            this.minimumLength = jsonObj.minimumLength;
        if (undefined !== jsonObj.maximumLength)
            this.maximumLength = jsonObj.maximumLength;
        this.readOnly = jsonObj.readOnly;
        this.kindOfQuantity = jsonObj.kindOfQuantity;
        this.isCustomHandled = jsonObj.isCustomHandled;
        if (undefined !== jsonObj.minOccurs)
            this.minOccurs = jsonObj.minOccurs;
        if (undefined !== jsonObj.maxOccurs)
            this.maxOccurs = jsonObj.maxOccurs;
        this.direction = jsonObj.direction;
        this.relationshipClass = jsonObj.relationshipClass;
        this.customAttributes = jsonObj.customAttributes;
    }
    /** Create a typed value, or array of values, from a factory and an input object */
    createValueOrArray(func, jsonObj) {
        if (undefined === this.minOccurs)
            return func(jsonObj); // not an array
        const val = [];
        jsonObj.forEach((element) => val.push(func(element)));
        return val;
    }
    /** construct a single property from an input object according to this metadata */
    createProperty(jsonObj) {
        if (jsonObj === undefined)
            return undefined;
        if (undefined !== this.primitiveType) {
            switch (this.primitiveType) {
                case PrimitiveTypeCode.Boolean:
                case PrimitiveTypeCode.Double:
                case PrimitiveTypeCode.Integer:
                case PrimitiveTypeCode.String:
                    return jsonObj; // this works even for arrays or strings that are JSON because the parsed JSON is already the right type
                case PrimitiveTypeCode.Point2d:
                    return this.createValueOrArray((obj) => core_geometry_1.Point2d.fromJSON(obj), jsonObj);
                case PrimitiveTypeCode.Point3d:
                    return this.createValueOrArray((obj) => core_geometry_1.Point3d.fromJSON(obj), jsonObj);
            }
        }
        if (this.isNavigation)
            return jsonObj.id !== undefined ? new ElementProps_1.RelatedElement(jsonObj) : core_bentley_1.Id64.fromJSON(jsonObj);
        return jsonObj;
    }
    /** Return `true` if this property is a NavigationProperty. */
    get isNavigation() {
        return (this.direction !== undefined); // the presence of `direction` means it is a navigation property
    }
}
exports.PropertyMetaData = PropertyMetaData;
/** Metadata for an Entity.
 * @beta
 * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `EntityClass` class from `@itwin/ecschema-metadata` instead.
 */
// eslint-disable-next-line @typescript-eslint/no-deprecated
class EntityMetaData {
    /** The Id of the class in the [[IModelDb]] from which the metadata was obtained. */
    classId;
    /** The Entity name */
    ecclass;
    description;
    modifier;
    displayLabel;
    /** The  base class that this class is derives from. If more than one, the first is the actual base class and the others are mixins. */
    baseClasses;
    /** The Custom Attributes for this class */
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    customAttributes;
    /** An object whose properties correspond by name to the properties of this class. */
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    properties;
    // eslint-disable-next-line @typescript-eslint/no-deprecated
    constructor(jsonObj) {
        this.classId = jsonObj.classId;
        this.ecclass = jsonObj.ecclass;
        this.description = jsonObj.description;
        this.modifier = jsonObj.modifier;
        this.displayLabel = jsonObj.displayLabel;
        this.baseClasses = jsonObj.baseClasses;
        this.customAttributes = jsonObj.customAttributes;
        this.properties = {};
        for (const propName in jsonObj.properties) { // eslint-disable-line guard-for-in
            // eslint-disable-next-line @typescript-eslint/no-deprecated
            this.properties[propName] = new PropertyMetaData(jsonObj.properties[propName]);
        }
    }
}
exports.EntityMetaData = EntityMetaData;
//# sourceMappingURL=EntityProps.js.map