# app/modules/hosting/definition.py
"""
Hosting module definition.

Web hosting, domains, email, and website building for Luxembourg businesses.
Manages POC → live website pipeline and operational service tracking.
Admin-only module for superadmin and platform admin users.
"""

from app.modules.base import (
    MenuItemDefinition,
    MenuSectionDefinition,
    ModuleDefinition,
    PermissionDefinition,
)
from app.modules.enums import FrontendType


def _get_admin_api_router():
    """Lazy import of admin API router to avoid circular imports."""
    from app.modules.hosting.routes.api.admin import router

    return router


def _get_admin_page_router():
    """Lazy import of admin page router to avoid circular imports."""
    from app.modules.hosting.routes.pages.admin import router

    return router


def _get_public_page_router():
    """Lazy import of public page router to avoid circular imports."""
    from app.modules.hosting.routes.pages.public import router

    return router


hosting_module = ModuleDefinition(
    code="hosting",
    name="Hosting",
    description="Web hosting, domains, email, and website building for Luxembourg businesses.",
    version="1.0.0",
    is_core=False,
    is_self_contained=True,
    requires=["prospecting"],
    permissions=[
        PermissionDefinition(
            id="hosting.view",
            label_key="hosting.permissions.view",
            description_key="hosting.permissions.view_desc",
            category="hosting",
        ),
        PermissionDefinition(
            id="hosting.manage",
            label_key="hosting.permissions.manage",
            description_key="hosting.permissions.manage_desc",
            category="hosting",
        ),
    ],
    features=[
        "hosting",
        "domains",
        "email",
        "ssl",
        "poc_sites",
    ],
    menu_items={
        FrontendType.ADMIN: [
            "hosting-dashboard",
            "hosting-sites",
            "hosting-clients",
        ],
    },
    menus={
        FrontendType.ADMIN: [
            MenuSectionDefinition(
                id="hosting",
                label_key="hosting.menu.hosting",
                icon="globe",
                order=65,
                items=[
                    MenuItemDefinition(
                        id="hosting-dashboard",
                        label_key="hosting.menu.dashboard",
                        icon="chart-bar",
                        route="/admin/hosting",
                        order=1,
                    ),
                    MenuItemDefinition(
                        id="hosting-sites",
                        label_key="hosting.menu.sites",
                        icon="globe",
                        route="/admin/hosting/sites",
                        order=5,
                    ),
                    MenuItemDefinition(
                        id="hosting-clients",
                        label_key="hosting.menu.clients",
                        icon="cube",
                        route="/admin/hosting/clients",
                        order=10,
                    ),
                ],
            ),
        ],
    },
    migrations_path="migrations",
    services_path="app.modules.hosting.services",
    models_path="app.modules.hosting.models",
    schemas_path="app.modules.hosting.schemas",
    exceptions_path="app.modules.hosting.exceptions",
    templates_path="templates",
    locales_path="locales",
    tasks_path="app.modules.hosting.tasks",
)


def get_hosting_module_with_routers() -> ModuleDefinition:
    """
    Get hosting module with routers attached.

    Attaches routers lazily to avoid circular imports during module initialization.
    """
    hosting_module.admin_api_router = _get_admin_api_router()
    hosting_module.admin_page_router = _get_admin_page_router()
    hosting_module.public_page_router = _get_public_page_router()
    return hosting_module


__all__ = ["hosting_module", "get_hosting_module_with_routers"]
