"""
AIOps KPI Dashboard — ADR-090 + MASTER §7.1
=============================================
GET /api/v1/aiops/kpi → 一次回傳 AI 自主化成熟度全景.

Router 層只負責 HTTP 路由,DB/business logic 由 AiopsKpiService 處理
(leWOOOgo 積木化鐵律: Router 禁直接存取 DB).

2026-04-19 ogt + Claude Opus 4.7 (1M context) Asia/Taipei
"""
from __future__ import annotations

from typing import Any

from fastapi import APIRouter

from src.services.aiops_kpi_service import get_aiops_kpi_service

router = APIRouter()


@router.get("/aiops/kpi", tags=["AIOps KPI"])
async def get_aiops_kpi() -> dict[str, Any]:
    """
    AI 自主化成熟度全景 KPI.

    一次返回 6 個 section + autonomy_score:
    - asset_inventory: 資產盤點 (by type + last_scan)
    - coverage_kpi: 7 維自動化覆蓋 SLO (green/yellow/red/unknown)
    - rule_quality: 規則品質 (noisy/deprecated/with_fires + top 5)
    - capacity_health: 主機容量健康 (ai_verdict 分布)
    - automation_flow_24h: 過去 24h aol 動作流量
    - ai_autonomy_score: 自主化總分 (0-100, 5 子項 × 20)
    """
    svc = get_aiops_kpi_service()
    return await svc.get_snapshot()
