// Copyright (c) 2020-2021, 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 "OgnInsertAttrDatabase.h"

namespace omni
{
namespace graph
{
namespace core
{

class OgnInsertAttr
{
public:
    // Copies all attributes from an input prim to the output prim, as well as copying an additional
    // "attrToInsert" attribute from the node itself with a specified name.
    static bool compute(OgnInsertAttrDatabase& db)
    {
        const auto& outputAttrNameToken = db.inputs.outputAttrName();
        const auto& inputBundle = db.inputs.data();
        auto& outputBundle = db.outputs.data();

        // Start by copying the input prim into the output prim.
        outputBundle = inputBundle;
        if (!outputBundle.isValid())
        {
            db.logWarning("Failed to copy input bundle to the output");
            return false;
        }

        const auto& inputToInsert = db.inputs.attrToInsert();
        if (!inputToInsert.isValid())
        {
            db.logWarning("Input attribute to insert is not valid");
            return false;
        }
        outputBundle.insertAttribute(inputToInsert, outputAttrNameToken);
        return true;
    }
};

REGISTER_OGN_NODE()

}
}
}
