"""Group module registrar."""

from __future__ import annotations

from typing import TYPE_CHECKING

from ai.backend.manager.api.rest.middleware.auth import superadmin_required
from ai.backend.manager.api.rest.routing import RouteRegistry

from .handler import GroupHandler

if TYPE_CHECKING:
    from ai.backend.manager.api.rest.types import RouteDeps


def register_group_routes(handler: GroupHandler, route_deps: RouteDeps) -> RouteRegistry:
    """Build the group sub-application."""

    reg = RouteRegistry.create("group", route_deps.cors_options)

    reg.add(
        "POST",
        "/registry-quota",
        handler.create_registry_quota,
        middlewares=[superadmin_required],
    )
    reg.add(
        "GET",
        "/registry-quota",
        handler.read_registry_quota,
        middlewares=[superadmin_required],
    )
    reg.add(
        "PATCH",
        "/registry-quota",
        handler.update_registry_quota,
        middlewares=[superadmin_required],
    )
    reg.add(
        "DELETE",
        "/registry-quota",
        handler.delete_registry_quota,
        middlewares=[superadmin_required],
    )
    return reg
