"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.OperationAlterTraitsPersistence = void 0;
const internal_1 = require("../../../internal");
const utils = require("./../utils");
const copyDataUtils = require("../../../Utilities/CopyDataUtils");
const OperationBasePersistence_1 = require("./OperationBasePersistence");
/**
 * Operation AlterTraits persistence
 */
class OperationAlterTraitsPersistence {
    static fromData(ctx, object) {
        if (!object) {
            return undefined;
        }
        const alterTraitsOp = OperationBasePersistence_1.OperationBasePersistence.fromData(ctx, internal_1.cdmObjectType.operationAlterTraitsDef, object);
        if (object.traitsToAdd !== undefined) {
            alterTraitsOp.traitsToAdd = new internal_1.CdmCollection(ctx, alterTraitsOp, internal_1.cdmObjectType.traitRef);
            utils.addArrayToCdmCollection(alterTraitsOp.traitsToAdd, utils.createTraitReferenceArray(ctx, object.traitsToAdd));
        }
        if (object.traitsToRemove !== undefined) {
            alterTraitsOp.traitsToRemove = new internal_1.CdmCollection(ctx, alterTraitsOp, internal_1.cdmObjectType.traitRef);
            utils.addArrayToCdmCollection(alterTraitsOp.traitsToRemove, utils.createTraitReferenceArray(ctx, object.traitsToRemove));
        }
        alterTraitsOp.argumentsContainWildcards = object.argumentsContainWildcards;
        if (typeof (object.applyTo) === 'string') {
            alterTraitsOp.applyTo = [object.applyTo];
        }
        else if (Array.isArray(object.applyTo)) {
            alterTraitsOp.applyTo = object.applyTo;
        }
        else if (object.applyTo !== undefined) {
            internal_1.Logger.error(ctx, this.TAG, this.fromData.name, undefined, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, "applyTo", "string or list of strings");
        }
        if (typeof (object.applyToTraits) === 'string') {
            alterTraitsOp.applyToTraits = [object.applyToTraits];
        }
        else if (Array.isArray(object.applyToTraits)) {
            alterTraitsOp.applyToTraits = object.applyToTraits;
        }
        else if (object.applyToTraits !== undefined) {
            internal_1.Logger.error(ctx, this.TAG, this.fromData.name, undefined, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, "applyToTraits", "string or list of strings");
        }
        return alterTraitsOp;
    }
    static toData(instance, resOpt, options) {
        if (!instance) {
            return undefined;
        }
        const data = OperationBasePersistence_1.OperationBasePersistence.toData(instance, resOpt, options);
        data.traitsToAdd = copyDataUtils.arrayCopyData(resOpt, instance.traitsToAdd, options);
        data.traitsToRemove = copyDataUtils.arrayCopyData(resOpt, instance.traitsToRemove, options);
        data.argumentsContainWildcards = instance.argumentsContainWildcards;
        data.applyTo = instance.applyTo;
        data.applyToTraits = instance.applyToTraits;
        return data;
    }
}
exports.OperationAlterTraitsPersistence = OperationAlterTraitsPersistence;
OperationAlterTraitsPersistence.TAG = OperationAlterTraitsPersistence.name;
//# sourceMappingURL=OperationAlterTraitsPersistence.js.map