/** Watch slot monitoring duration options (minutes). */

export type WatchTtlMinutes = 30 | 60 | 120 | 480 | 1440

export const WATCH_TTL_DEFAULT_MINUTES: WatchTtlMinutes = 30

export const WATCH_TTL_OPTIONS: { minutes: WatchTtlMinutes; label: string }[] = [
  { minutes: 30, label: '30分' },
  { minutes: 60, label: '1时' },
  { minutes: 120, label: '2时' },
  { minutes: 480, label: '8时' },
  { minutes: 1440, label: '24时' },
]

export function normalizeWatchTtlMinutes(raw: number | null | undefined): WatchTtlMinutes {
  const allowed = new Set(WATCH_TTL_OPTIONS.map((o) => o.minutes))
  if (raw != null && allowed.has(raw as WatchTtlMinutes)) return raw as WatchTtlMinutes
  if (raw === 8) return 480
  if (raw === 24) return 1440
  return WATCH_TTL_DEFAULT_MINUTES
}

export function watchTtlLabel(minutes: WatchTtlMinutes): string {
  return WATCH_TTL_OPTIONS.find((o) => o.minutes === minutes)?.label ?? `${minutes}分`
}

export function watchTtlShortLabel(minutes: WatchTtlMinutes): string {
  const map: Record<WatchTtlMinutes, string> = {
    30: '30分钟',
    60: '1小时',
    120: '2小时',
    480: '8小时',
    1440: '24小时',
  }
  return map[minutes] ?? `${minutes}分钟`
}
