"""Support for simplified access to data on nodes of type omni.graph.nodes.RpResourceExampleAllocator

Allocate CUDA-interoperable RpResource
"""

import numpy

import omni.graph.core as og
import omni.graph.core._omni_graph_core as _og
import omni.graph.tools.ogn as ogn



class OgnRpResourceExampleAllocatorDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.graph.nodes.RpResourceExampleAllocator

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.points
            inputs.primPath
            inputs.reload
            inputs.stream
            inputs.verbose
        Outputs:
            outputs.pointCountCollection
            outputs.primPathCollection
            outputs.reload
            outputs.resourcePointerCollection
            outputs.stream
    """

    # Imprint the generator and target ABI versions in the file for JIT generation
    GENERATOR_VERSION = (1, 41, 3)
    TARGET_VERSION = (2, 139, 12)

    # This is an internal object that provides per-class storage of a per-node data dictionary
    PER_NODE_DATA = {}

    # This is an internal object that describes unchanging attributes in a generic way
    # The values in this list are in no particular order, as a per-attribute tuple
    #     Name, Type, ExtendedTypeIndex, UiName, Description, Metadata,
    #     Is_Required, DefaultValue, Is_Deprecated, DeprecationMsg
    # You should not need to access any of this data directly, use the defined database interfaces
    INTERFACE = og.Database._get_interface([
        ('inputs:points', 'float3[]', 0, 'Prim Points', 'Points attribute input. Points and a prim path may be supplied directly as an alternative to a bundle input.', {}, True, [], False, ''),
        ('inputs:primPath', 'token', 0, 'Prim path input', 'Prim path input. Points and a prim path may be supplied directly as an alternative to a bundle input.', {}, True, "", False, ''),
        ('inputs:reload', 'bool', 0, 'Reload', 'Force RpResource reload', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('inputs:stream', 'uint64', 0, 'stream', 'Pointer to the CUDA Stream', {}, True, 0, False, ''),
        ('inputs:verbose', 'bool', 0, 'Verbose', 'verbose printing', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:pointCountCollection', 'uint64[]', 0, 'Point Counts', 'Point count for each prim being deformed', {}, True, None, False, ''),
        ('outputs:primPathCollection', 'token[]', 0, 'Prim Paths', 'Path for each prim being deformed', {}, True, None, False, ''),
        ('outputs:reload', 'bool', 0, 'Reload', 'Force RpResource reload', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:resourcePointerCollection', 'uint64[]', 0, 'Resource Pointer Collection', 'Pointers to RpResources \n(two resources per prim are allocated -- one for rest positions and one for deformed positions)', {}, True, None, False, ''),
        ('outputs:stream', 'uint64', 0, 'stream', 'Pointer to the CUDA Stream', {}, True, None, False, ''),
    ])

    class ValuesForInputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to input attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self._batchedReadAttributes = []
            self._batchedReadValues = []

        @property
        def points(self):
            data_view = og.AttributeValueHelper(self._attributes.points)
            return data_view.get()

        @points.setter
        def points(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.points)
            data_view = og.AttributeValueHelper(self._attributes.points)
            data_view.set(value)
            self.points_size = data_view.get_array_size()

        @property
        def primPath(self):
            data_view = og.AttributeValueHelper(self._attributes.primPath)
            return data_view.get()

        @primPath.setter
        def primPath(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.primPath)
            data_view = og.AttributeValueHelper(self._attributes.primPath)
            data_view.set(value)

        @property
        def reload(self):
            data_view = og.AttributeValueHelper(self._attributes.reload)
            return data_view.get()

        @reload.setter
        def reload(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.reload)
            data_view = og.AttributeValueHelper(self._attributes.reload)
            data_view.set(value)

        @property
        def stream(self):
            data_view = og.AttributeValueHelper(self._attributes.stream)
            return data_view.get()

        @stream.setter
        def stream(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.stream)
            data_view = og.AttributeValueHelper(self._attributes.stream)
            data_view.set(value)

        @property
        def verbose(self):
            data_view = og.AttributeValueHelper(self._attributes.verbose)
            return data_view.get()

        @verbose.setter
        def verbose(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.verbose)
            data_view = og.AttributeValueHelper(self._attributes.verbose)
            data_view.set(value)

        def _prefetch(self):
            readAttributes = self._batchedReadAttributes
            newValues = _og._prefetch_input_attributes_data(readAttributes)
            if len(readAttributes) == len(newValues):
                self._batchedReadValues = newValues

    class ValuesForOutputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to output attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self.pointCountCollection_size = None
            self.primPathCollection_size = None
            self.resourcePointerCollection_size = None
            self._batchedWriteValues = { }

        @property
        def pointCountCollection(self):
            data_view = og.AttributeValueHelper(self._attributes.pointCountCollection)
            return data_view.get(reserved_element_count=self.pointCountCollection_size)

        @pointCountCollection.setter
        def pointCountCollection(self, value):
            data_view = og.AttributeValueHelper(self._attributes.pointCountCollection)
            data_view.set(value)
            self.pointCountCollection_size = data_view.get_array_size()

        @property
        def primPathCollection(self):
            data_view = og.AttributeValueHelper(self._attributes.primPathCollection)
            return data_view.get(reserved_element_count=self.primPathCollection_size)

        @primPathCollection.setter
        def primPathCollection(self, value):
            data_view = og.AttributeValueHelper(self._attributes.primPathCollection)
            data_view.set(value)
            self.primPathCollection_size = data_view.get_array_size()

        @property
        def reload(self):
            data_view = og.AttributeValueHelper(self._attributes.reload)
            return data_view.get()

        @reload.setter
        def reload(self, value):
            data_view = og.AttributeValueHelper(self._attributes.reload)
            data_view.set(value)

        @property
        def resourcePointerCollection(self):
            data_view = og.AttributeValueHelper(self._attributes.resourcePointerCollection)
            return data_view.get(reserved_element_count=self.resourcePointerCollection_size)

        @resourcePointerCollection.setter
        def resourcePointerCollection(self, value):
            data_view = og.AttributeValueHelper(self._attributes.resourcePointerCollection)
            data_view.set(value)
            self.resourcePointerCollection_size = data_view.get_array_size()

        @property
        def stream(self):
            data_view = og.AttributeValueHelper(self._attributes.stream)
            return data_view.get()

        @stream.setter
        def stream(self, value):
            data_view = og.AttributeValueHelper(self._attributes.stream)
            data_view.set(value)

        def _commit(self):
            _og._commit_output_attributes_data(self._batchedWriteValues)
            self._batchedWriteValues = { }

    class ValuesForState(og.DynamicAttributeAccess):
        """Helper class that creates natural hierarchical access to state attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)

    def __init__(self, node):
        super().__init__(node)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_INPUT)
        self.inputs = OgnRpResourceExampleAllocatorDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnRpResourceExampleAllocatorDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnRpResourceExampleAllocatorDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
