/**
 * 어구 위반 G코드 카탈로그 (DAR-03)
 *
 * SSOT: prediction/algorithms/gear_violation.py
 * 사용처: GearDetection, GearDetailPanel
 */

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

export type GearViolationCode = 'G-01' | 'G-02' | 'G-03' | 'G-04' | 'G-05' | 'G-06';

interface GearViolationMeta {
  code: GearViolationCode;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
  desc: { ko: string; en: string };
  score: number;
}

export const GEAR_VIOLATION_CODES: Record<GearViolationCode, GearViolationMeta> = {
  'G-01': {
    code: 'G-01',
    i18nKey: 'gearViolation.G01',
    fallback: { ko: '수역 위반', en: 'Zone Violation' },
    intent: 'high',
    desc: { ko: '비허가 수역에서 조업', en: 'Fishing in unauthorized zone' },
    score: 15,
  },
  'G-02': {
    code: 'G-02',
    i18nKey: 'gearViolation.G02',
    fallback: { ko: '금어기 위반', en: 'Closed Season' },
    intent: 'high',
    desc: { ko: '금어기 내 조업', en: 'Fishing during closed season' },
    score: 15,
  },
  'G-03': {
    code: 'G-03',
    i18nKey: 'gearViolation.G03',
    fallback: { ko: '미등록 어구', en: 'Unregistered Gear' },
    intent: 'warning',
    desc: { ko: '등록되지 않은 어구 사용', en: 'Unregistered gear in use' },
    score: 10,
  },
  'G-04': {
    code: 'G-04',
    i18nKey: 'gearViolation.G04',
    fallback: { ko: 'MMSI 조작', en: 'MMSI Tampering' },
    intent: 'critical',
    desc: { ko: '어구 신호 주기적 단속 (조작 의심)', en: 'Gear signal on/off cycling' },
    score: 10,
  },
  'G-05': {
    code: 'G-05',
    i18nKey: 'gearViolation.G05',
    fallback: { ko: '어구 이동', en: 'Gear Drift' },
    intent: 'warning',
    desc: { ko: '고정 어구 인위적 이동 (조류보정 초과)', en: 'Fixed gear artificial repositioning' },
    score: 5,
  },
  'G-06': {
    code: 'G-06',
    i18nKey: 'gearViolation.G06',
    fallback: { ko: '쌍끌이 공조', en: 'Pair Trawl' },
    intent: 'critical',
    desc: { ko: '쌍끌이 트롤 공조 불법조업', en: 'Cooperative pair trawl fishing' },
    score: 20,
  },
};

export function getGearViolationIntent(code: string): BadgeIntent {
  return GEAR_VIOLATION_CODES[code as GearViolationCode]?.intent ?? 'muted';
}

export function getGearViolationLabel(
  code: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = GEAR_VIOLATION_CODES[code as GearViolationCode];
  if (!meta) return code;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}

export function getGearViolationDesc(
  code: string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = GEAR_VIOLATION_CODES[code as GearViolationCode];
  if (!meta) return '';
  return meta.desc[lang];
}
