"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.OperationBasePersistence = void 0;
const internal_1 = require("../../../internal");
class OperationBasePersistence {
    static fromData(ctx, objectType, object) {
        if (!object) {
            return undefined;
        }
        const operation = ctx.corpus.MakeObject(objectType);
        const operationType = internal_1.OperationTypeConvertor.fromObjectType(objectType);
        const operationName = internal_1.OperationTypeConvertor.operationTypeToString(operationType);
        if (object.$type && !internal_1.StringUtils.equalsWithIgnoreCase(object.$type, operationName)) {
            internal_1.Logger.error(ctx, this.TAG, this.fromData.name, undefined, internal_1.cdmLogCode.ErrPersistProjInvalidOpsType, object.$type);
        }
        else {
            operation.type = operationType;
        }
        operation.condition = object.condition;
        operation.explanation = object.explanation;
        operation.sourceInput = object.sourceInput;
        return operation;
    }
    static toData(instance, resOpt, options) {
        if (!instance) {
            return undefined;
        }
        return {
            $type: internal_1.OperationTypeConvertor.operationTypeToString(instance.type),
            condition: instance.condition,
            explanation: instance.explanation,
            sourceInput: instance.sourceInput
        };
    }
}
exports.OperationBasePersistence = OperationBasePersistence;
OperationBasePersistence.TAG = OperationBasePersistence.name;
//# sourceMappingURL=OperationBasePersistence.js.map