"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.E2ERelationshipPersistence = void 0;
const internal_1 = require("../../internal");
const copyDataUtils = require("../../Utilities/CopyDataUtils");
const utils = require("./utils");
class E2ERelationshipPersistence {
    static fromData(ctx, dataObj) {
        const relationship = ctx.corpus.MakeObject(internal_1.cdmObjectType.e2eRelationshipDef);
        if (!internal_1.StringUtils.isNullOrWhiteSpace(dataObj.name)) {
            relationship.name = dataObj.name;
        }
        relationship.fromEntity = dataObj.fromEntity;
        relationship.fromEntityAttribute = dataObj.fromEntityAttribute;
        relationship.toEntity = dataObj.toEntity;
        relationship.toEntityAttribute = dataObj.toEntityAttribute;
        utils.addArrayToCdmCollection(relationship.exhibitsTraits, utils.createTraitReferenceArray(ctx, dataObj.exhibitsTraits));
        return relationship;
    }
    static toData(instance, resOpt, options) {
        return {
            name: !internal_1.StringUtils.isNullOrWhiteSpace(instance.name) ? instance.name : undefined,
            fromEntity: instance.fromEntity,
            fromEntityAttribute: instance.fromEntityAttribute,
            toEntity: instance.toEntity,
            toEntityAttribute: instance.toEntityAttribute,
            exhibitsTraits: copyDataUtils.arrayCopyData(resOpt, instance.exhibitsTraits, options)
        };
    }
}
exports.E2ERelationshipPersistence = E2ERelationshipPersistence;
//# sourceMappingURL=E2ERelationshipPersistence.js.map