/**
 * AI 엔진 심각도 카탈로그
 *
 * 일반 위험도(AlertLevel)와 다른 별도 분류 체계.
 * 단일 값(CRITICAL, HIGH 등) 외에도 **범위 표기**를 지원: 'HIGH~CRITICAL', 'MEDIUM~CRITICAL'.
 *
 * 사용처: AIModelManagement (탐지 엔진별 심각도 표기)
 *
 * 향후 확장 가능: prediction_engine 메타데이터, MLOps 모델별 임계치 정보
 */

import type { BadgeIntent } from '@lib/theme/variants';

export type EngineSeverity =
  | 'CRITICAL'
  | 'HIGH~CRITICAL'
  | 'HIGH'
  | 'MEDIUM~CRITICAL'
  | 'MEDIUM'
  | 'LOW'
  | '-';

interface EngineSeverityMeta {
  code: EngineSeverity;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
}

export const ENGINE_SEVERITIES: Record<EngineSeverity, EngineSeverityMeta> = {
  'CRITICAL': {
    code: 'CRITICAL',
    i18nKey: 'engineSeverity.CRITICAL',
    fallback: { ko: '심각', en: 'Critical' },
    intent: 'critical',
  },
  'HIGH~CRITICAL': {
    code: 'HIGH~CRITICAL',
    i18nKey: 'engineSeverity.HIGH_CRITICAL',
    fallback: { ko: '높음~심각', en: 'High~Critical' },
    intent: 'critical',
  },
  'HIGH': {
    code: 'HIGH',
    i18nKey: 'engineSeverity.HIGH',
    fallback: { ko: '높음', en: 'High' },
    intent: 'high',
  },
  'MEDIUM~CRITICAL': {
    code: 'MEDIUM~CRITICAL',
    i18nKey: 'engineSeverity.MEDIUM_CRITICAL',
    fallback: { ko: '보통~심각', en: 'Medium~Critical' },
    intent: 'high',
  },
  'MEDIUM': {
    code: 'MEDIUM',
    i18nKey: 'engineSeverity.MEDIUM',
    fallback: { ko: '보통', en: 'Medium' },
    intent: 'warning',
  },
  'LOW': {
    code: 'LOW',
    i18nKey: 'engineSeverity.LOW',
    fallback: { ko: '낮음', en: 'Low' },
    intent: 'info',
  },
  '-': {
    code: '-',
    i18nKey: 'engineSeverity.NONE',
    fallback: { ko: '-', en: '-' },
    intent: 'muted',
  },
};

export function getEngineSeverityMeta(sev: string): EngineSeverityMeta {
  return ENGINE_SEVERITIES[sev as EngineSeverity] ?? ENGINE_SEVERITIES['-'];
}

export function getEngineSeverityIntent(sev: string): BadgeIntent {
  return getEngineSeverityMeta(sev).intent;
}

export function getEngineSeverityLabel(
  sev: string,
  t: (key: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = getEngineSeverityMeta(sev);
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}
