/**
 * 모선 추론(Parent Resolution) 상태 + 라벨 세션 상태 카탈로그
 *
 * SSOT: backend gear_group_parent_resolution.status
 * 사용처: ParentReview, LabelSession, RealGearGroups
 */

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

// ─── 부모 해석(Resolution) 상태 ──────────────
export type ParentResolutionStatus = 'UNRESOLVED' | 'MANUAL_CONFIRMED' | 'REVIEW_REQUIRED';

interface ParentResolutionMeta {
  code: ParentResolutionStatus;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
}

export const PARENT_RESOLUTION_STATUSES: Record<ParentResolutionStatus, ParentResolutionMeta> = {
  UNRESOLVED: {
    code: 'UNRESOLVED',
    i18nKey: 'parentResolution.UNRESOLVED',
    fallback: { ko: '미해결', en: 'Unresolved' },
    intent: 'warning',
  },
  REVIEW_REQUIRED: {
    code: 'REVIEW_REQUIRED',
    i18nKey: 'parentResolution.REVIEW_REQUIRED',
    fallback: { ko: '검토 필요', en: 'Review Required' },
    intent: 'critical',
  },
  MANUAL_CONFIRMED: {
    code: 'MANUAL_CONFIRMED',
    i18nKey: 'parentResolution.MANUAL_CONFIRMED',
    fallback: { ko: '수동 확정', en: 'Manually Confirmed' },
    intent: 'success',
  },
};

export function getParentResolutionIntent(s: string): BadgeIntent {
  return PARENT_RESOLUTION_STATUSES[s as ParentResolutionStatus]?.intent ?? 'muted';
}
export function getParentResolutionLabel(
  s: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = PARENT_RESOLUTION_STATUSES[s as ParentResolutionStatus];
  if (!meta) return s;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}

// ─── 라벨 세션 상태 ──────────────
export type LabelSessionStatus = 'ACTIVE' | 'CANCELLED' | 'COMPLETED';

interface LabelSessionMeta {
  code: LabelSessionStatus;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
}

export const LABEL_SESSION_STATUSES: Record<LabelSessionStatus, LabelSessionMeta> = {
  ACTIVE: {
    code: 'ACTIVE',
    i18nKey: 'labelSession.ACTIVE',
    fallback: { ko: '진행중', en: 'Active' },
    intent: 'success',
  },
  COMPLETED: {
    code: 'COMPLETED',
    i18nKey: 'labelSession.COMPLETED',
    fallback: { ko: '완료', en: 'Completed' },
    intent: 'info',
  },
  CANCELLED: {
    code: 'CANCELLED',
    i18nKey: 'labelSession.CANCELLED',
    fallback: { ko: '취소', en: 'Cancelled' },
    intent: 'muted',
  },
};

export function getLabelSessionIntent(s: string): BadgeIntent {
  return LABEL_SESSION_STATUSES[s as LabelSessionStatus]?.intent ?? 'muted';
}
export function getLabelSessionLabel(
  s: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = LABEL_SESSION_STATUSES[s as LabelSessionStatus];
  if (!meta) return s;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}
