from flut._flut.engine import FlutRealtimeObject, FlutStaticObject
from flut._flut.runtime import _flut_unpack_required_field


class SchedulerBinding(FlutRealtimeObject, FlutStaticObject):

    def __init__(self, oid: int):
        super().__init__("SchedulerBinding", oid=oid)

    @staticmethod
    def _flut_unpack(data: dict) -> "SchedulerBinding":
        return SchedulerBinding(oid=_flut_unpack_required_field(data, "_flut_oid"))

    @staticmethod
    def instance() -> "SchedulerBinding":
        return FlutStaticObject._static_call("SchedulerBinding", "instance")

    def addPostFrameCallback(self, callback):
        action_id = self._register_oneshot_action(lambda *args: callback(None))
        self._call_void("addPostFrameCallback", callbackId=action_id)
