"""
Implementation of the Python node adding attributes with a given description to an output bundle.
"""
import omni.graph.core as og


class OgnTutorialBundleAddAttributesPy:
    """Exercise the bundled data types through a Python OmniGraph node"""

    @staticmethod
    def compute(db) -> bool:
        """Implements the same algorithm as the C++ node OgnTutorialBundleAddAttributes.cpp using the Python
        bindings to the bundle method
        """
        # Start with an empty output bundle.
        output_bundle = db.outputs.bundle
        output_bundle.clear()

        if db.inputs.useBatchedAPI:
            attr_types = [og.AttributeType.type_from_ogn_type_name(type_name) for type_name in db.inputs.typesToAdd]
            output_bundle.add_attributes(attr_types, db.inputs.addedAttributeNames)

            output_bundle.remove_attributes(db.inputs.removedAttributeNames)

        else:
            for attribute_type_name, attribute_name in zip(db.inputs.typesToAdd, db.inputs.addedAttributeNames):
                attribute_type = og.AttributeType.type_from_ogn_type_name(attribute_type_name)
                output_bundle.insert((attribute_type, attribute_name))

            # Remove attributes from the bundle that were already added. This is a somewhat contrived operation that
            # allows testing of both adding and removal within a simple environment.
            for attribute_name in db.inputs.removedAttributeNames:
                output_bundle.remove(attribute_name)

        return True
