# app/modules/prospecting/definition.py
"""
Prospecting module definition.

Lead discovery, scoring, and campaign management for Luxembourg businesses.
Supports digital (domain scanning) and offline (street/networking) lead channels.
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.prospecting.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.prospecting.routes.pages.admin import router

    return router


prospecting_module = ModuleDefinition(
    code="prospecting",
    name="Prospecting",
    description="Lead discovery, scoring, and campaign management for Luxembourg businesses.",
    version="1.0.0",
    is_core=False,
    is_self_contained=True,
    permissions=[
        PermissionDefinition(
            id="prospecting.view",
            label_key="prospecting.permissions.view",
            description_key="prospecting.permissions.view_desc",
            category="prospecting",
        ),
        PermissionDefinition(
            id="prospecting.manage",
            label_key="prospecting.permissions.manage",
            description_key="prospecting.permissions.manage_desc",
            category="prospecting",
        ),
        PermissionDefinition(
            id="prospecting.scan",
            label_key="prospecting.permissions.scan",
            description_key="prospecting.permissions.scan_desc",
            category="prospecting",
        ),
        PermissionDefinition(
            id="prospecting.campaigns",
            label_key="prospecting.permissions.campaigns",
            description_key="prospecting.permissions.campaigns_desc",
            category="prospecting",
        ),
        PermissionDefinition(
            id="prospecting.export",
            label_key="prospecting.permissions.export",
            description_key="prospecting.permissions.export_desc",
            category="prospecting",
        ),
    ],
    features=[
        "domain_scanning",
        "offline_capture",
        "opportunity_scoring",
        "campaign_management",
        "lead_export",
    ],
    menu_items={
        FrontendType.ADMIN: [
            "prospecting-dashboard",
            "prospects",
            "leads",
            "capture",
            "scan-jobs",
            "campaigns",
        ],
    },
    menus={
        FrontendType.ADMIN: [
            MenuSectionDefinition(
                id="prospecting",
                label_key="prospecting.menu.prospecting",
                icon="cursor-click",
                order=60,
                items=[
                    MenuItemDefinition(
                        id="prospecting-dashboard",
                        label_key="prospecting.menu.dashboard",
                        icon="chart-bar",
                        route="/admin/prospecting",
                        order=1,
                    ),
                    MenuItemDefinition(
                        id="prospects",
                        label_key="prospecting.menu.prospects",
                        icon="globe",
                        route="/admin/prospecting/prospects",
                        order=5,
                    ),
                    MenuItemDefinition(
                        id="leads",
                        label_key="prospecting.menu.leads",
                        icon="cursor-click",
                        route="/admin/prospecting/leads",
                        order=10,
                    ),
                    MenuItemDefinition(
                        id="capture",
                        label_key="prospecting.menu.capture",
                        icon="phone",
                        route="/admin/prospecting/capture",
                        order=15,
                    ),
                    MenuItemDefinition(
                        id="scan-jobs",
                        label_key="prospecting.menu.scan_jobs",
                        icon="globe-alt",
                        route="/admin/prospecting/scan-jobs",
                        order=20,
                    ),
                    MenuItemDefinition(
                        id="campaigns",
                        label_key="prospecting.menu.campaigns",
                        icon="mail",
                        route="/admin/prospecting/campaigns",
                        order=25,
                    ),
                ],
            ),
        ],
    },
    migrations_path="migrations",
    services_path="app.modules.prospecting.services",
    models_path="app.modules.prospecting.models",
    schemas_path="app.modules.prospecting.schemas",
    exceptions_path="app.modules.prospecting.exceptions",
    templates_path="templates",
    locales_path="locales",
    tasks_path="app.modules.prospecting.tasks",
)


def get_prospecting_module_with_routers() -> ModuleDefinition:
    """
    Get prospecting module with routers attached.

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


__all__ = ["prospecting_module", "get_prospecting_module_with_routers"]
