"""
Alert Type Mapping Constants
=============================
alertname → incident_type 靜態對應表

來源: BUG-008 修復 2026-04-11（9筆 → 56筆，涵蓋 alerts-unified.yml 全部 alertname）
遷移: M3 2026-04-11 — 從 webhooks.py 內聯 dict 抽至此模組

整合狀態 (I1, 2026-04-11): ADR-064 Rule Engine 已整合，見 alert_rule_engine.get_incident_type()。
此靜態 dict 為 Layer 2 fallback：YAML incident_type（Layer 1）→ 此 dict → "custom"（Layer 3）。
擴展方式：在 alert_rules.yaml 中新增 incident_type 欄位；此 dict 僅需補無 YAML 規則的 alertname。
"""

# alertname → incident_type 對應（56 筆）
ALERTNAME_TO_TYPE: dict[str, str] = {
    # --- 主機層 (host_alerts) ---
    "HostDown":                          "host_down",
    "HostHighCpuLoad":                   "host_cpu",
    "HostOutOfMemory":                   "host_memory",
    "HostOutOfDiskSpace":                "disk_full",
    "HostBackupFailed":                  "backup_failure",
    # --- K8s 層 (kubernetes_alerts) ---
    "K3sNodeNotReady":                   "k8s_node_failure",
    "KubePodCrashLooping":               "k8s_pod_crash",
    "KubePodNotReady":                   "k8s_pod_crash",
    "KubeNodeNotReady":                  "k8s_node_failure",
    "KubeNodeUnreachable":               "k8s_node_failure",
    "KubeDeploymentReplicasMismatch":    "k8s_deployment_mismatch",
    "VeleroBackupFailed":                "backup_failure",
    "VeleroBackupNotRun":                "backup_failure",
    # --- 資料庫 (database_alerts / database_detail_alerts) ---
    "PostgreSQLDown":                    "database_down",
    "RedisDown":                         "database_down",
    "PostgreSQLHighConnections":         "database_performance",
    "RedisMemoryHigh":                   "high_memory",
    "PostgreSQLSlowQueries":             "database_performance",
    "PostgreSQLDeadlocks":               "database_performance",
    "PostgreSQLTooManyConnections":      "database_performance",
    "RedisKeyEviction":                  "database_performance",
    "RedisConnectionsHigh":              "database_performance",
    "RedisCommandLatencyHigh":           "database_performance",
    # --- 服務可用性 (service_alerts) ---
    "OpenClawDown":                      "service_down",
    "SignOzDown":                        "service_down",
    "SentryDown":                        "service_down",
    "HarborDown":                        "service_down",
    "GiteaDown":                         "service_down",
    "AlertmanagerDown":                  "service_down",
    "MinIODown":                         "service_down",
    "KaliScannerDown":                   "service_down",
    # --- 外部網站 (external_website_alerts) ---
    "MoWoooWorkDown":                    "service_404",
    "TsenyangWebsiteDown":               "service_404",
    "StockWoooWorkDown":                 "service_404",
    "BitanWoooWorkDown":                 "service_404",
    "ExternalSiteSSLExpiringSoon":       "ssl_expiry",
    # --- 告警鏈路 (alert_chain) ---
    "AlertChainBroken_Alertmanager":     "alert_chain_broken",
    "AlertChainBroken_Sentry":           "alert_chain_broken",
    "NoAlertsReceived2Hours":            "alert_chain_broken",
    "AlertChainUnhealthy":               "alert_chain_broken",
    # --- Docker 容器 (docker_health_alerts) ---
    "DockerContainerUnhealthy":          "docker_container_unhealthy",
    "DockerContainerExited":             "docker_container_unhealthy",
    # --- 自動修復監控 (auto_repair) ---
    "AutoRepairLowSuccessRate":          "auto_repair_degraded",
    "PermanentFixRequired":              "auto_repair_degraded",
    # --- 舊版相容 ---
    "HighCPUUsage":                      "high_cpu",
    "HighMemoryUsage":                   "high_memory",
    "DiskSpaceLow":                      "disk_full",
    "SSLCertExpiringSoon":               "ssl_expiry",
    "TargetDown":                        "service_404",
}
