"""Router agregador del módulo CRM.

Se monta bajo el prefijo ``/crm`` en ``api/v1/router.py``.
Importar este módulo también registra los permisos del CRM (side-effect de
``permissions``), siguiendo el patrón del ``PermissionRegistry``.
"""

from fastapi import APIRouter, Depends

from api.v1.modules.core.permissions.dependencies import PermissionChecker

from . import permissions  # noqa: F401  (side-effect: registra permisos del CRM)
from .accounts.routes import router as accounts_router
from .activities.routes import router as activities_router
from .addresses.routes import router as addresses_router
from .cases.routes import router as cases_router
from .catalogs.routes import router as catalogs_router
from .contacts.routes import router as contacts_router
from .documents.routes import router as documents_router
from .expediente_gateway.routes import router as expediente_gateway_router
from .leads.routes import router as leads_router
from .metrics.routes import router as metrics_router
from .opportunities.routes import router as opportunities_router
from .pipelines.routes import router as pipelines_router
from .quotes.routes import router as quotes_router
from .rates.routes import cost_router as rates_cost_router
from .rates.routes import router as rates_router
from .service_requests.routes import router as service_requests_router
from .suppliers.routes import router as suppliers_router
from .uploads.routes import router as uploads_router

# Enforcement por área/carril (R-T-07): se exige el permiso crm.access para tocar
# cualquier endpoint del módulo. En desarrollo el usuario se auto-bootstrapea a
# super_admin (ver PermissionChecker) para no bloquear el entorno.
router = APIRouter(dependencies=[Depends(PermissionChecker(["crm.access"]))])

router.include_router(accounts_router)
router.include_router(suppliers_router)
router.include_router(contacts_router)
router.include_router(addresses_router)
router.include_router(documents_router)
router.include_router(service_requests_router)
router.include_router(quotes_router)
router.include_router(leads_router)
router.include_router(pipelines_router)
router.include_router(opportunities_router)
router.include_router(activities_router)
router.include_router(cases_router)
router.include_router(metrics_router)
router.include_router(catalogs_router)
router.include_router(uploads_router)
router.include_router(rates_router)
router.include_router(rates_cost_router)
# Tablero de operación del carril hacia EFC: cola pendiente, métricas y reintento manual.
# No es una ruta de negocio; existe para que una persona vea y desatore la entrega sin
# entrar a la base. Hereda el enforcement de crm.access del router agregador.
router.include_router(expediente_gateway_router)
