// Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <OgnComputeErrorCppDatabase.h>
#include <omni/graph/core/IInternal.h>

#include <string>

class OgnComputeErrorCpp
{
public:
    static void initialize(const GraphContextObj& context, const NodeObj& nodeObj)
    {
        const AttributeObj& attrObj = nodeObj.iNode->getAttribute(nodeObj, "inputs:deprecatedInInit");
        const IInternal* iInternal = carb::getCachedInterface<omni::graph::core::IInternal>();

        // We would not normally deprecate an attribute this way. It would be done through the .ogn file.
        // This is just for testing purposes.
        iInternal->deprecateAttribute(attrObj, "Use 'dummyIn' instead.");
    }

    static bool compute(OgnComputeErrorCppDatabase& db)
    {
        auto severity = db.inputs.severity();
        auto failCompute = db.inputs.failCompute();
        std::string message(db.inputs.message());

        db.outputs.dummyOut() = db.inputs.dummyIn();

        if (severity == db.tokens.warning)
        {
            db.logWarning(message.c_str());
        }
        else if (severity == db.tokens.error)
        {
            db.logError(message.c_str());
        }
        return !failCompute;
    }
};

REGISTER_OGN_NODE()
