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": "13.7",
        "commercial_product": "Torbat Healthcare",
        "features": {
            "foundation": True,
            "health": True,
            "capabilities": True,
            "metrics": True,
            "external_providers_ready": True,
            "clinics": True,
            "branches": True,
            "departments": True,
            "doctors": True,
            "patients": True,
            "appointments": True,
            "schedules": True,
            "availability": True,
            "waiting_list": True,
            "visits": True,
            "doctor_panel": True,
            "clinic_management": True,
            "patient_portal": True,
            "medical_records": True,
            "pharmacy": True,
            "delivery_integration": True,
            "ai": False,
        },
        "independence": {
            "standalone": True,
            "superapp": True,
            "integrations": [
                "accounting",
                "communication",
                "loyalty",
                "crm",
                "delivery",
                "storage",
                "identity",
                "ai",
            ],
            "integration_mode": "api_and_events_only",
        },
    }


@router.get("/metrics")
async def metrics():
    return {
        "service": settings.service_name,
        "version": __version__,
        "phase": "13.7",
        "metrics": {
            "clinics": "tenant_scoped",
            "branches": "tenant_scoped",
            "departments": "tenant_scoped",
            "doctors": "tenant_scoped",
            "patients": "tenant_scoped",
            "external_providers": "tenant_scoped",
            "configurations": "tenant_scoped",
            "settings": "tenant_scoped",
            "outbox_events": "tenant_scoped",
            "appointments": "tenant_scoped",
            "visits": "tenant_scoped",
            "encounters": "tenant_scoped",
            "pharmacy_orders": "tenant_scoped",
            "delivery_job_intents": "tenant_scoped",
        },
        "note": "Healthcare phases 13.0–13.7 complete",
    }
