"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.TraitPersistence = void 0;
const __1 = require("..");
const internal_1 = require("../../internal");
const copyDataUtils = require("../../Utilities/CopyDataUtils");
const utils = require("./utils");
class TraitPersistence {
    static fromData(ctx, object) {
        const trait = ctx.corpus.MakeObject(internal_1.cdmObjectType.traitDef, object.traitName);
        if (object.extendsTrait) {
            trait.extendsTrait = __1.CdmFolder.TraitReferencePersistence.fromData(ctx, object.extendsTrait);
        }
        if (object.explanation) {
            trait.explanation = object.explanation;
        }
        if (object.hasParameters) {
            object.hasParameters.forEach((ap) => {
                if (typeof (ap) !== 'string') {
                    trait.parameters.push(__1.CdmFolder.ParameterPersistence.fromData(ctx, ap));
                }
            });
        }
        if (object.elevated !== undefined) {
            trait.elevated = object.elevated;
        }
        if (object.ugly !== undefined) {
            trait.ugly = object.ugly;
        }
        if (object.associatedProperties) {
            trait.associatedProperties = object.associatedProperties;
        }
        if (object.defaultVerb) {
            trait.defaultVerb = __1.CdmFolder.TraitReferencePersistence.fromData(ctx, object.defaultVerb);
        }
        utils.addArrayToCdmCollection(trait.exhibitsTraits, utils.createTraitReferenceArray(ctx, object.exhibitsTraits));
        return trait;
    }
    static toData(instance, resOpt, options) {
        const result = {
            traitName: instance.traitName,
            extendsTrait: instance.extendsTrait ? instance.extendsTrait.copyData(resOpt, options) : undefined,
            hasParameters: copyDataUtils.arrayCopyData(resOpt, instance.parameters, options)
        };
        if (instance.associatedProperties !== undefined) {
            result.associatedProperties = instance.associatedProperties;
        }
        if (instance.elevated !== undefined) {
            result.elevated = instance.elevated;
        }
        if (instance.explanation !== undefined) {
            result.explanation = instance.explanation;
        }
        if (instance.ugly !== undefined) {
            result.ugly = instance.ugly;
        }
        if (instance.defaultVerb !== undefined) {
            result.defaultVerb = instance.defaultVerb.copyData(resOpt, options);
        }
        result.exhibitsTraits = copyDataUtils.arrayCopyData(resOpt, instance.exhibitsTraits, options);
        return result;
    }
}
exports.TraitPersistence = TraitPersistence;
//# sourceMappingURL=TraitPersistence.js.map