"""
Implementation of an stateful OmniGraph node that enables 1 branch or another using dynamic scheduling
"""


class OgnDynamicSwitch:
    @staticmethod
    def compute(db):
        db.node.set_dynamic_downstream_control(True)
        left_out_attr = db.node.get_attribute("outputs:left_out")
        right_out_attr = db.node.get_attribute("outputs:right_out")
        if db.inputs.switch > 0:
            left_out_attr.set_disable_dynamic_downstream_work(True)
            right_out_attr.set_disable_dynamic_downstream_work(False)
        else:
            left_out_attr.set_disable_dynamic_downstream_work(False)
            right_out_attr.set_disable_dynamic_downstream_work(True)

        db.outputs.left_out = db.inputs.left_value
        db.outputs.right_out = db.inputs.right_value

        return True
