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

This is a tutorial node. It creates both an input and output attribute of every simple supported data type. The values are
modified in a simple way so that the compute modifies values.
"""

import carb

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



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

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.a_bool
            inputs.a_constant_input
            inputs.a_double
            inputs.a_float
            inputs.a_half
            inputs.a_int
            inputs.a_int64
            inputs.a_objectId
            inputs.a_path
            inputs.a_string
            inputs.a_token
            inputs.unsigned_a_uchar
            inputs.unsigned_a_uint
            inputs.unsigned_a_uint64
        Outputs:
            outputs.a_bool
            outputs.a_double
            outputs.a_float
            outputs.a_half
            outputs.a_int
            outputs.a_int64
            outputs.a_objectId
            outputs.a_path
            outputs.a_string
            outputs.a_token
            outputs.unsigned_a_uchar
            outputs.unsigned_a_uint
            outputs.unsigned_a_uint64
    """

    # 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:a_bool', 'bool', 0, 'Sample Boolean Input', 'This is an attribute of type boolean', {ogn.MetadataKeys.DEFAULT: 'true'}, True, True, False, ''),
        ('inputs:a_constant_input', 'int', 0, None, 'This is an input attribute whose value can be set but can only be connected as a source.', {ogn.MetadataKeys.OUTPUT_ONLY: '1'}, True, 0, False, ''),
        ('inputs:a_double', 'double', 0, None, 'This is an attribute of type 64 bit floating point', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:a_float', 'float', 0, None, 'This is an attribute of type 32 bit floating point', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:a_half', 'half', 0, 'Sample Half Precision Input', 'This is an attribute of type 16 bit float', {ogn.MetadataKeys.DEFAULT: '0.0'}, True, 0.0, False, ''),
        ('inputs:a_int', 'int', 0, None, 'This is an attribute of type 32 bit integer', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:a_int64', 'int64', 0, None, 'This is an attribute of type 64 bit integer', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:a_objectId', 'objectId', 0, None, 'This is an attribute of type objectId', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:a_path', 'path', 0, None, 'This is an attribute of type path', {ogn.MetadataKeys.DEFAULT: '""'}, True, "", False, ''),
        ('inputs:a_string', 'string', 0, None, 'This is an attribute of type string', {ogn.MetadataKeys.DEFAULT: '"helloString"'}, True, "helloString", False, ''),
        ('inputs:a_token', 'token', 0, None, 'This is an attribute of type interned string with fast comparison and hashing', {ogn.MetadataKeys.DEFAULT: '"helloToken"'}, True, "helloToken", False, ''),
        ('inputs:unsigned:a_uchar', 'uchar', 0, None, 'This is an attribute of type unsigned 8 bit integer', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:unsigned:a_uint', 'uint', 0, None, 'This is an attribute of type unsigned 32 bit integer', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('inputs:unsigned:a_uint64', 'uint64', 0, None, 'This is an attribute of type unsigned 64 bit integer', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:a_bool', 'bool', 0, 'Sample Boolean Output', 'This is a computed attribute of type boolean', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:a_double', 'double', 0, None, 'This is a computed attribute of type 64 bit floating point', {ogn.MetadataKeys.DEFAULT: '5.0'}, True, 5.0, False, ''),
        ('outputs:a_float', 'float', 0, None, 'This is a computed attribute of type 32 bit floating point', {ogn.MetadataKeys.DEFAULT: '4.0'}, True, 4.0, False, ''),
        ('outputs:a_half', 'half', 0, 'Sample Half Precision Output', 'This is a computed attribute of type 16 bit float', {ogn.MetadataKeys.DEFAULT: '1.0'}, True, 1.0, False, ''),
        ('outputs:a_int', 'int', 0, None, 'This is a computed attribute of type 32 bit integer', {ogn.MetadataKeys.DEFAULT: '2'}, True, 2, False, ''),
        ('outputs:a_int64', 'int64', 0, None, 'This is a computed attribute of type 64 bit integer', {ogn.MetadataKeys.DEFAULT: '3'}, True, 3, False, ''),
        ('outputs:a_objectId', 'objectId', 0, None, 'This is a computed attribute of type objectId', {ogn.MetadataKeys.DEFAULT: '8'}, True, 8, False, ''),
        ('outputs:a_path', 'path', 0, None, 'This is a computed attribute of type path', {ogn.MetadataKeys.DEFAULT: '"/"'}, True, "/", False, ''),
        ('outputs:a_string', 'string', 0, None, 'This is a computed attribute of type string', {ogn.MetadataKeys.DEFAULT: '"seven"'}, True, "seven", False, ''),
        ('outputs:a_token', 'token', 0, None, 'This is a computed attribute of type interned string with fast comparison and hashing', {ogn.MetadataKeys.DEFAULT: '"six"'}, True, "six", False, ''),
        ('outputs:unsigned:a_uchar', 'uchar', 0, None, 'This is a computed attribute of type unsigned 8 bit integer', {ogn.MetadataKeys.DEFAULT: '9'}, True, 9, False, ''),
        ('outputs:unsigned:a_uint', 'uint', 0, None, 'This is a computed attribute of type unsigned 32 bit integer', {ogn.MetadataKeys.DEFAULT: '10'}, True, 10, False, ''),
        ('outputs:unsigned:a_uint64', 'uint64', 0, None, 'This is a computed attribute of type unsigned 64 bit integer', {ogn.MetadataKeys.DEFAULT: '11'}, True, 11, False, ''),
    ])

    @classmethod
    def _populate_role_data(cls):
        """Populate a role structure with the non-default roles on this node type"""
        role_data = super()._populate_role_data()
        role_data.inputs.a_objectId = og.AttributeRole.OBJECT_ID
        role_data.inputs.a_path = og.AttributeRole.PATH
        role_data.inputs.a_string = og.AttributeRole.TEXT
        role_data.outputs.a_objectId = og.AttributeRole.OBJECT_ID
        role_data.outputs.a_path = og.AttributeRole.PATH
        role_data.outputs.a_string = og.AttributeRole.TEXT
        return role_data

    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 a_bool(self):
            data_view = og.AttributeValueHelper(self._attributes.a_bool)
            return data_view.get()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @unsigned_a_uint64.setter
        def unsigned_a_uint64(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.unsigned_a_uint64)
            data_view = og.AttributeValueHelper(self._attributes.unsigned_a_uint64)
            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.a_path_size = 1
            self.a_string_size = 5
            self._batchedWriteValues = { }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @unsigned_a_uint64.setter
        def unsigned_a_uint64(self, value):
            data_view = og.AttributeValueHelper(self._attributes.unsigned_a_uint64)
            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 = OgnTutorialSimpleDataDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnTutorialSimpleDataDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnTutorialSimpleDataDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
