from .application_setup import ApplicationSetup
from .viewport_rendering import enable_viewport_rendering


def register_actions(extension_id: str, application_setup: ApplicationSetup):
    """
    Register actions.
    Args:
        extension_id (str): Extension ID which actions belongs to
        application_setup: Instance of application_setup
    """
    try:
        import omni.kit.actions.core

        action_registry = omni.kit.actions.core.get_action_registry()
        actions_tag = "app.setup"

        action_registry.register_action(
            extension_id,
            "active_workflow",
            lambda name: application_setup.active_workflow(name),
            display_name="Active workflow",
            description="Active workflow",
            tag=actions_tag,
        )

        action_registry.register_action(
            extension_id,
            "enable_viewport_rendering",
            lambda: enable_viewport_rendering(),
            display_name="Enable viewport rendering",
            description="Enable viewport rendering",
            tag=actions_tag,
        )
    except ImportError:
        pass


def deregister_actions(extension_id: str):
    """
    Deregister actions.
    Args:
        extension_id (str): Extension ID whcih actions belongs to
    """
    try:
        import omni.kit.actions.core

        action_registry = omni.kit.actions.core.get_action_registry()
        action_registry.deregister_all_actions_for_extension(extension_id)
    except ImportError:
        pass