"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");
class TraitReferencePersistence extends cdmObjectRefPersistence_1.cdmObjectRefPersistence {
    static fromData(ctx, object) {
        if (!object) {
            return;
        }
        let simpleReference = true;
        let optional;
        let trait;
        let args;
        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);
            }
        }
        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));
            });
        }
        return traitReference;
    }
}
exports.TraitReferencePersistence = TraitReferencePersistence;
//# sourceMappingURL=TraitReferencePersistence.js.map