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

Node to vectorize data by paths passed in via input. PROTOTYPE DO NOT USE. Requires GatherPrototype
"""

import omni.graph.core as og
import omni.graph.core._omni_graph_core as _og
import omni.graph.tools.ogn as ogn
import numpy
class OgnGatherByPathDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.graph.nodes.GatherByPath

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.allAttributes
            inputs.attributes
            inputs.checkResyncAttributes
            inputs.forceExportToHistory
            inputs.hydraFastPath
            inputs.primPaths
            inputs.shouldWriteBack
        Outputs:
            outputs.gatherId
            outputs.gatheredPaths

    Predefined Tokens:
        tokens.Disabled
        tokens.World
        tokens.Local
    """
    # 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:allAttributes', 'bool', 0, None, "When true, all USD attributes will be gathered. Otherwise those specified by 'attributes' will be gathered.", {ogn.MetadataKeys.DEFAULT: 'true'}, True, True, False, ''),
        ('inputs:attributes', 'string', 0, None, 'A space-separated list of attribute names to be gathered when allAttributes is false', {}, True, '', False, ''),
        ('inputs:checkResyncAttributes', 'bool', 0, None, 'When true, the data vectorization will be updated when new attributes to the Prims are added.', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('inputs:forceExportToHistory', 'bool', 0, None, 'When true, all USD gathered paths will be tagged for being exported to the history.', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('inputs:hydraFastPath', 'token', 0, None, "When not 'Disabled', will extract USD Geometry transforms into Hydra fast-path attributes.\n'World' will add _worldPosition, _worldOrientation. 'Local' will add _localMatrix.", {ogn.MetadataKeys.ALLOWED_TOKENS: 'Disabled,World,Local', ogn.MetadataKeys.ALLOWED_TOKENS_RAW: '["Disabled", "World", "Local"]', ogn.MetadataKeys.DEFAULT: '"Disabled"'}, True, 'Disabled', False, ''),
        ('inputs:primPaths', 'token[]', 0, None, 'A list of Prim paths whose data should be vectorized', {}, True, [], False, ''),
        ('inputs:shouldWriteBack', 'bool', 0, 'Should Write Back To USD', 'Write the data back into USD if true.', {ogn.MetadataKeys.DEFAULT: 'false'}, True, False, False, ''),
        ('outputs:gatherId', 'uint64', 0, None, 'The GatherId corresponding to this Gather, kInvalidGatherId if the Gather failed', {}, True, None, False, ''),
        ('outputs:gatheredPaths', 'token[]', 0, None, 'The list of gathered prim paths in gathered-order', {}, True, None, False, ''),
    ])
    class tokens:
        Disabled = "Disabled"
        World = "World"
        Local = "Local"
    class ValuesForInputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = {"allAttributes", "attributes", "checkResyncAttributes", "forceExportToHistory", "hydraFastPath", "shouldWriteBack", "_setting_locked", "_batchedReadAttributes", "_batchedReadValues"}
        """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._attributes.allAttributes, self._attributes.attributes, self._attributes.checkResyncAttributes, self._attributes.forceExportToHistory, self._attributes.hydraFastPath, self._attributes.shouldWriteBack]
            self._batchedReadValues = [True, "", False, False, "Disabled", False]

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

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

        @property
        def allAttributes(self):
            return self._batchedReadValues[0]

        @allAttributes.setter
        def allAttributes(self, value):
            self._batchedReadValues[0] = value

        @property
        def attributes(self):
            return self._batchedReadValues[1]

        @attributes.setter
        def attributes(self, value):
            self._batchedReadValues[1] = value

        @property
        def checkResyncAttributes(self):
            return self._batchedReadValues[2]

        @checkResyncAttributes.setter
        def checkResyncAttributes(self, value):
            self._batchedReadValues[2] = value

        @property
        def forceExportToHistory(self):
            return self._batchedReadValues[3]

        @forceExportToHistory.setter
        def forceExportToHistory(self, value):
            self._batchedReadValues[3] = value

        @property
        def hydraFastPath(self):
            return self._batchedReadValues[4]

        @hydraFastPath.setter
        def hydraFastPath(self, value):
            self._batchedReadValues[4] = value

        @property
        def shouldWriteBack(self):
            return self._batchedReadValues[5]

        @shouldWriteBack.setter
        def shouldWriteBack(self, value):
            self._batchedReadValues[5] = value

        def __getattr__(self, item: str):
            if item in self.LOCAL_PROPERTY_NAMES:
                return object.__getattribute__(self, item)
            else:
                return super().__getattr__(item)

        def __setattr__(self, item: str, new_value):
            if item in self.LOCAL_PROPERTY_NAMES:
                object.__setattr__(self, item, new_value)
            else:
                super().__setattr__(item, new_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 = {"gatherId", "_batchedWriteValues"}
        """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.gatheredPaths_size = None
            self._batchedWriteValues = { }

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

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

        @property
        def gatherId(self):
            value = self._batchedWriteValues.get(self._attributes.gatherId)
            if value:
                return value
            else:
                data_view = og.AttributeValueHelper(self._attributes.gatherId)
                return data_view.get()

        @gatherId.setter
        def gatherId(self, value):
            self._batchedWriteValues[self._attributes.gatherId] = value

        def __getattr__(self, item: str):
            if item in self.LOCAL_PROPERTY_NAMES:
                return object.__getattribute__(self, item)
            else:
                return super().__getattr__(item)

        def __setattr__(self, item: str, new_value):
            if item in self.LOCAL_PROPERTY_NAMES:
                object.__setattr__(self, item, new_value)
            else:
                super().__setattr__(item, new_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 = OgnGatherByPathDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnGatherByPathDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnGatherByPathDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
