from fastapi import APIRouter

from app import __version__
from app.core.config import settings

router = APIRouter()


@router.get("/health")
async def health_check():
    return {
        "status": "ok",
        "service": settings.service_name,
        "version": __version__,
    }


@router.get("/capabilities")
async def capabilities():
    return {
        "service": settings.service_name,
        "version": __version__,
        "phase": "10.8",
        "commercial_product": "Torbat Driver",
        "features": {
            "foundation": True,
            "health": True,
            "capabilities": True,
            "metrics": True,
            "external_providers_ready": True,
            "future_routing_engines_ready": True,
            "drivers": True,
            "driver_lifecycle": True,
            "driver_credentials": True,
            "driver_documents": True,
            "fleet": True,
            "vehicle_types": True,
            "vehicles": True,
            "vehicle_assignments": True,
            "driver_availability": True,
            "shifts": True,
            "working_zones": True,
            "pricing_rules": True,
            "capabilities_catalog": True,
            "capability_bundles": True,
            "dispatch_engine": True,
            "routing_engine": True,
            "optimization_runs": True,
            "tracking": True,
            "proof_of_delivery": True,
            "customer_tracking": True,
            "settlement": True,
            "ai": False,
        },
        "independence": {
            "standalone": True,
            "superapp": True,
            "integrations": [
                "accounting",
                "communication",
                "loyalty",
                "crm",
                "hospitality",
                "marketplace",
                "sports_center",
                "clinic",
                "pharmacy",
            ],
            "integration_mode": "api_and_events_only",
            "accounting_mode": "settlement_refs_only",
            "no_journal_entries_in_delivery_db": True,
        },
    }


@router.get("/metrics")
async def metrics():
    """Phase 10.8 metrics discovery — tenant-scoped counters."""
    return {
        "service": settings.service_name,
        "version": __version__,
        "phase": "10.8",
        "metrics": {
            "organizations": "tenant_scoped",
            "hubs": "tenant_scoped",
            "drivers": "tenant_scoped",
            "fleets": "tenant_scoped",
            "vehicles": "tenant_scoped",
            "shifts": "tenant_scoped",
            "pricing_rules": "tenant_scoped",
            "dispatch_jobs": "tenant_scoped",
            "route_plans": "tenant_scoped",
            "optimization_runs": "tenant_scoped",
            "tracking_sessions": "tenant_scoped",
            "proof_of_delivery": "tenant_scoped",
            "settlement_intents": "tenant_scoped",
            "outbox_events": "tenant_scoped",
        },
        "note": "Full delivery platform through phase 10.8; settlement uses AccountingProvider refs only",
    }
