"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.AttributeGroupPersistence = void 0;
const __1 = require("..");
const internal_1 = require("../../internal");
const copyDataUtils = require("../../Utilities/CopyDataUtils");
const utils = require("./utils");
class AttributeGroupPersistence {
    static fromData(ctx, object, entityName) {
        const attributeGroup = ctx.corpus.MakeObject(internal_1.cdmObjectType.attributeGroupDef, object.attributeGroupName);
        if (object.explanation) {
            attributeGroup.explanation = object.explanation;
        }
        attributeGroup.attributeContext = __1.CdmFolder.AttributeContextReferencePersistence.fromData(ctx, object.attributeContext);
        utils.addArrayToCdmCollection(attributeGroup.exhibitsTraits, utils.createTraitReferenceArray(ctx, object.exhibitsTraits));
        if (object.members) {
            for (const att of object.members) {
                attributeGroup.members.push(utils.createAttribute(ctx, att, entityName));
            }
        }
        return attributeGroup;
    }
    static toData(instance, resOpt, options) {
        return {
            explanation: instance.explanation,
            attributeGroupName: instance.attributeGroupName,
            exhibitsTraits: copyDataUtils.arrayCopyData(resOpt, instance.exhibitsTraits.allItems, options),
            attributeContext: instance.
                attributeContext ? instance.attributeContext.copyData(resOpt, options) : undefined,
            members: copyDataUtils.
                arrayCopyData(resOpt, instance.members, options) || []
        };
    }
}
exports.AttributeGroupPersistence = AttributeGroupPersistence;
//# sourceMappingURL=AttributeGroupPersistence.js.map