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