"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.TraitReferencePersistence = void 0;
const __1 = require("..");
const internal_1 = require("../../internal");
const cdmObjectRefPersistence_1 = require("./cdmObjectRefPersistence");
const utils = require("./utils");
class TraitReferencePersistence extends cdmObjectRefPersistence_1.cdmObjectRefPersistence {
    static fromData(ctx, object) {
        if (!object) {
            return;
        }
        let simpleReference = true;
        let optional;
        let trait;
        let args;
        let trVerb = undefined;
        let appliedTraits = undefined;
        if (typeof (object) === 'string') {
            trait = object;
        }
        else {
            simpleReference = false;
            optional = object.optional;
            args = object.arguments;
            if (typeof (object.traitReference) === 'string') {
                trait = object.traitReference;
            }
            else {
                trait = __1.CdmFolder.TraitPersistence.fromData(ctx, object.traitReference);
            }
            trVerb = TraitReferencePersistence.fromData(ctx, object.verb);
            appliedTraits = utils.createTraitReferenceArray(ctx, object.appliedTraits);
        }
        const traitReference = ctx.corpus.MakeRef(internal_1.cdmObjectType.traitRef, trait, simpleReference);
        if (optional !== undefined) {
            traitReference.optional = optional;
        }
        if (args) {
            args.forEach((a) => {
                traitReference.arguments.push(__1.CdmFolder.ArgumentPersistence.fromData(ctx, a));
            });
        }
        traitReference.verb = trVerb;
        utils.addArrayToCdmCollection(traitReference.appliedTraits, appliedTraits);
        return traitReference;
    }
}
exports.TraitReferencePersistence = TraitReferencePersistence;
//# sourceMappingURL=TraitReferencePersistence.js.map