from __future__ import annotations

from sqlalchemy.ext.asyncio import AsyncSession

from shared.events import register_activity_handler
from shared.models.federation import APActivity
from shared.services.navigation import rebuild_navigation


async def on_child_attached(activity: APActivity, session: AsyncSession) -> None:
    await rebuild_navigation(session)


async def on_child_detached(activity: APActivity, session: AsyncSession) -> None:
    await rebuild_navigation(session)


register_activity_handler("Add", on_child_attached, object_type="rose:ContainerRelation")
register_activity_handler("Remove", on_child_detached, object_type="rose:ContainerRelation")
