"""Support for simplified access to data on nodes of type omni.syntheticdata.SdFrameIdentifier

Synthetic Data node to expose pipeline frame identifier.
"""


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



class OgnSdFrameIdentifierDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.syntheticdata.SdFrameIdentifier

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.exec
            inputs.renderResults
        Outputs:
            outputs.durationDenominator
            outputs.durationNumerator
            outputs.exec
            outputs.externalTimeOfSimNs
            outputs.frameNumber
            outputs.rationalTimeOfSimDenominator
            outputs.rationalTimeOfSimNumerator
            outputs.sampleTimeOffsetInSimFrames
            outputs.type

    Predefined Tokens:
        tokens.NoFrameNumber
        tokens.FrameNumber
        tokens.ConstantFramerateFrameNumber
    """

    # 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:exec', 'execution', 0, None, 'Trigger', {}, True, None, False, ''),
        ('inputs:renderResults', 'uint64', 0, None, 'Render results', {}, True, 0, False, ''),
        ('outputs:durationDenominator', 'uint64', 0, None, 'Duration denominator.\nOnly valid if eConstantFramerateFrameNumber', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:durationNumerator', 'int64', 0, None, 'Duration numerator.\nOnly valid if eConstantFramerateFrameNumber.', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:exec', 'execution', 0, 'Received', 'Executes for each newFrame event received', {}, True, None, False, ''),
        ('outputs:externalTimeOfSimNs', 'int64', 0, None, 'External time in Ns.\nOnly valid if eConstantFramerateFrameNumber.', {ogn.MetadataKeys.DEFAULT: '-1'}, True, -1, False, ''),
        ('outputs:frameNumber', 'int64', 0, None, 'Frame number.\nValid if eFrameNumber or eConstantFramerateFrameNumber.', {ogn.MetadataKeys.DEFAULT: '-1'}, True, -1, False, ''),
        ('outputs:rationalTimeOfSimDenominator', 'uint64', 0, None, 'rational time of simulation denominator.', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:rationalTimeOfSimNumerator', 'int64', 0, None, 'rational time of simulation numerator.', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:sampleTimeOffsetInSimFrames', 'uint64', 0, None, 'Sample time offset.\nOnly valid if eConstantFramerateFrameNumber.', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:type', 'token', 0, None, 'Type of the frame identifier.', {ogn.MetadataKeys.ALLOWED_TOKENS: 'NoFrameNumber,FrameNumber,ConstantFramerateFrameNumber', ogn.MetadataKeys.ALLOWED_TOKENS_RAW: '["NoFrameNumber", "FrameNumber", "ConstantFramerateFrameNumber"]', ogn.MetadataKeys.DEFAULT: '"NoFrameNumber"'}, True, "NoFrameNumber", False, ''),
    ])

    class tokens:
        NoFrameNumber = "NoFrameNumber"
        FrameNumber = "FrameNumber"
        ConstantFramerateFrameNumber = "ConstantFramerateFrameNumber"

    @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.exec = og.AttributeRole.EXECUTION
        role_data.outputs.exec = og.AttributeRole.EXECUTION
        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 exec(self):
            data_view = og.AttributeValueHelper(self._attributes.exec)
            return data_view.get()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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