from __future__ import annotations

from flownet.config import FlownetConfig
import flownet.api
from flownet.runtime.runtime import get_runtime
from flownet.runtime.kernel import get_runtime_kernel
from flownet.platform.container_manager_actor import ContainerManagerActor
from flownet.proactive.manager_actor import (
    SERVICE_MANAGER_ACTOR_ID,
    CONTAINER_EVENT_SERVICE_NAME,
)
from flownet.platform.services.container_event_stream import container_event_stream


NODE_DAEMON_ACTOR_ID = "__daemon__"


def bootstrap_node_runtime(config: FlownetConfig, node_id: str | None = None):
    flownet.api.configure_runtime(config)
    runtime = get_runtime()
    kernel = get_runtime_kernel()
    node_control = kernel.require_node_control()
    node_control.require_service().attach_container_controller(
        ContainerManagerActor(runtime=runtime, node_id=node_id),
    )
    kernel.start_service(CONTAINER_EVENT_SERVICE_NAME, container_event_stream)
    # TODO: Register additional platform services here (events, logs, stream bridge).
    return runtime


__all__ = [
    "NODE_DAEMON_ACTOR_ID",
    "bootstrap_node_runtime",
    "SERVICE_MANAGER_ACTOR_ID",
    "CONTAINER_EVENT_SERVICE_NAME",
]
