// Copyright (c) 2022, 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 <OgnIsEmptyDatabase.h>
#include <omni/graph/core/ogn/ComputeHelpers.h>
#include <omni/graph/core/ogn/Types.h>
#include <string>
#include "PrimCommon.h"

namespace omni
{
namespace graph
{
namespace nodes
{

class OgnIsEmpty
{
public:
    static bool compute(OgnIsEmptyDatabase& db)
    {
        const auto& variable = db.inputs.input();
        auto& type = variable.type();

        switch (type.baseType)
        {
            case BaseDataType::eBool:
            case BaseDataType::eUChar:
            case BaseDataType::eInt:
            case BaseDataType::eUInt:
            case BaseDataType::eInt64:
            case BaseDataType::eUInt64:
            case BaseDataType::eHalf:
            case BaseDataType::eFloat:
            case BaseDataType::eDouble:
            {
                db.outputs.isEmpty() = variable.size() == 0;
                return true;
            }
            case BaseDataType::eToken:
            {
                std::string converted = tryConvertToString<ogn::Token>(db, variable);
                db.outputs.isEmpty() = converted.length() == 0;
                return true;
            }
            default:
            {
                db.logError("Type %s not supported", getOgnTypeName(type).c_str());
            }
        }

        return false;
    }
};

REGISTER_OGN_NODE()

} // nodes
} // graph
} // omni
