"""
Implementation of a Python node that uses state attributes to maintain information between evaluations.

The node has a simple monotonically increasing state output "monotonic" that can be reset by setting the state
attribute "reset" to true.
"""


class OgnTutorialStateAttributesPy:
    """Use internal node state information in addition to inputs"""

    @staticmethod
    def compute(db) -> bool:
        """Compute the output based on inputs and internal state"""

        # State attributes are the only ones guaranteed to remember and modify their values.
        # Care must be taken to set proper defaults when the node initializes, otherwise you could be
        # starting in an unknown state.
        if db.state.reset:
            db.state.monotonic = 0
            db.state.reset = False
        else:
            db.state.monotonic = db.state.monotonic + 1

        return True
