"""
Contextra AI Analytics — COCO 클래스 카탈로그 (중립 모듈)

역할:
  - canonical zero-based class_id ↔ class_key 매핑의 단일 진실(SSOT).
  - multi_pipeline(GStreamer import 포함)에서 분리해, capability 계산·
    시나리오 활성화 해석 등 가벼운 경로에서도 안전하게 사용 가능하게 한다.

참고:
  - RFBUILD-07: background를 제외한 canonical class_id는 0-based다.
  - 미지 id는 "class_<id>"로 폴백 (실패를 조용히 삼키지 않음).
"""

from __future__ import annotations

COCO_NAMES: list[str] = [
    "person","bicycle","car","motorcycle","airplane","bus","train","truck","boat",
    "traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat",
    "dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack",
    "umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball",
    "kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket",
    "bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple",
    "sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair",
    "couch","potted plant","bed","dining table","toilet","tv","laptop","mouse","remote",
    "keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book",
    "clock","vase","scissors","teddy bear","hair drier","toothbrush",
]


def class_key(class_id: int) -> str:
    """Canonical class_id(0-based) → business-safe class_key."""
    cid = int(class_id)
    if 0 <= cid < len(COCO_NAMES):
        return COCO_NAMES[cid]
    return f"class_{cid}"


def coco_name(class_id: int) -> str:
    """Compatibility alias for the canonical class_key lookup."""
    return class_key(class_id)


def coco_class_ids() -> list[int]:
    """det 모델이 출력할 수 있는 canonical class id 목록 (0..79)."""
    return list(range(len(COCO_NAMES)))
