"""AIOps 全景時序 endpoint — 為 P2.5 frontend 提供完整 incident → learn 鏈路

GET /api/v1/aiops/timeline
  回傳每個 Incident 的 6 階段 timeline（alert / diagnose / decide / execute / verify / learn）

積木化合規：DB 存取在 services/aiops_timeline_service.py，本 router 只做 HTTP 路由。

# 2026-04-27 Wave8-X3 by Claude — critic B4 timeline endpoint
"""

from __future__ import annotations

from typing import Any

from fastapi import APIRouter, Query

from src.services.aiops_timeline_service import fetch_aiops_timeline

router = APIRouter()


@router.get("/aiops/timeline", tags=["AIOps Timeline"])
async def get_aiops_timeline(
    incident_id: str | None = Query(None, description="指定單一 Incident ID"),
    hours: int = Query(24, ge=1, le=168, description="回溯小時數（1-168）"),
    severity: str | None = Query(None, description="嚴重度過濾（P0/P1/P2/P3）"),
) -> list[dict[str, Any]]:
    """回傳 Incident 6 階段全景 timeline。"""
    return await fetch_aiops_timeline(
        incident_id=incident_id,
        hours=hours,
        severity=severity,
    )
