"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.DataTypeReferencePersistence = void 0;
const internal_1 = require("../../internal");
const __1 = require("..");
const cdmObjectRefPersistence_1 = require("./cdmObjectRefPersistence");
const utils = require("./utils");
class DataTypeReferencePersistence extends cdmObjectRefPersistence_1.cdmObjectRefPersistence {
    static fromData(ctx, object) {
        if (!object) {
            return;
        }
        let simpleReference = true;
        let optional;
        let dataType;
        let appliedTraits;
        if (typeof (object) === 'string') {
            dataType = object;
        }
        else {
            simpleReference = false;
            optional = object.optional;
            if (typeof (object.dataTypeReference) === 'string') {
                dataType = object.dataTypeReference;
            }
            else {
                dataType = __1.CdmFolder.DataTypePersistence.fromData(ctx, object.dataTypeReference);
            }
        }
        const dataTypeReference = ctx.corpus.MakeRef(internal_1.cdmObjectType.dataTypeRef, dataType, simpleReference);
        if (optional !== undefined) {
            dataTypeReference.optional = optional;
        }
        if (typeof (object) !== 'string') {
            appliedTraits = utils.createTraitReferenceArray(ctx, object.appliedTraits);
        }
        utils.addArrayToCdmCollection(dataTypeReference.appliedTraits, appliedTraits);
        return dataTypeReference;
    }
}
exports.DataTypeReferencePersistence = DataTypeReferencePersistence;
//# sourceMappingURL=DataTypeReferencePersistence.js.map