# app/api/v1/admin/__init__.py
"""
Admin API router aggregation.

This module combines auto-discovered module routes for the admin API.

All admin routes are now auto-discovered from modules:
- tenancy: auth, admin_users, users, merchants, platforms, stores, store_domains, modules, module_config
- core: dashboard, settings, menu_config
- messaging: messages, notifications, email-templates
- monitoring: logs, tasks, tests, code_quality, audit, platform-health
- billing: subscriptions, invoices, payments
- inventory: stock management
- orders: order management, fulfillment, exceptions
- marketplace: letzshop integration, product sync
- catalog: store product catalog
- cms: content-pages, images, media, store-themes
- customers: customer management

IMPORTANT:
- This router is for JSON API endpoints only
- HTML page routes are mounted separately in main.py
- Module routes are auto-discovered from app/modules/{module}/routes/api/admin.py
"""

from fastapi import APIRouter

# Create admin router
router = APIRouter()


# ============================================================================
# Auto-discovered Module Routes
# ============================================================================
# All routes from self-contained modules are auto-discovered and registered.
# Legacy routes have been migrated to their respective modules:
# - menu_config -> core module
# - modules, module_config -> tenancy module

from app.modules.routes import get_admin_api_routes

for route_info in get_admin_api_routes():
    # Only pass prefix if custom_prefix is set (router already has internal prefix)
    if route_info.custom_prefix:
        router.include_router(
            route_info.router,
            prefix=route_info.custom_prefix,
            tags=route_info.tags,
        )
    else:
        router.include_router(
            route_info.router,
            tags=route_info.tags,
        )

# Export the router
__all__ = ["router"]
