"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);
        alterTraitsOp.traitsToAdd = utils.createTraitReferenceArray(ctx, object.traitsToAdd);
        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, null, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, internal_1.cdmLogCode.ErrPersistProjUnsupportedProp, "applyTo", "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;
        return data;
    }
}
exports.OperationAlterTraitsPersistence = OperationAlterTraitsPersistence;
OperationAlterTraitsPersistence.TAG = OperationAlterTraitsPersistence.name;
//# sourceMappingURL=OperationAlterTraitsPersistence.js.map