import type { ZoneId } from "../../zone/model/meta";
import type { VesselTypeCode } from "./types";

export const SPEED_MAX = 15;

export const MONTH_LABELS = [
  "1월",
  "2월",
  "3월",
  "4월",
  "5월",
  "6월",
  "7월",
  "8월",
  "9월",
  "10월",
  "11월",
  "12월",
] as const;

export interface SpeedSegment {
  label: string;
  range: [number, number];
  typicalSpeed: number;
  color: string;
  primary?: boolean;
}

export interface VesselTypeMeta {
  code: VesselTypeCode;
  name: string;
  count: number;
  allowedZones: ZoneId[];
  color: string;
  icon: string;
  speedProfile: SpeedSegment[];
  monthlyIntensity: number[]; // 12 months (0 = closed)
  trajectory: string;
}

export const VESSEL_TYPE_ORDER: VesselTypeCode[] = ["PT", "PT-S", "GN", "OT", "PS", "FC"];

export const VESSEL_TYPES: Record<VesselTypeCode, VesselTypeMeta> = {
  PT: {
    code: "PT",
    name: "2척식 저인망(본선)",
    count: 323,
    allowedZones: ["2", "3"],
    color: "#2563EB",
    icon: "⛵",
    speedProfile: [
      { label: "정박", range: [0, 0.5], typicalSpeed: 0.3, color: "#64748B" },
      { label: "투양망", range: [1, 2.5], typicalSpeed: 1.5, color: "#F59E0B" },
      { label: "예인조업", range: [2.5, 4.5], typicalSpeed: 3.3, color: "#2563EB", primary: true },
      { label: "저속", range: [4.5, 7], typicalSpeed: 5.5, color: "#8B5CF6" },
      { label: "고속", range: [7, 15], typicalSpeed: 8.3, color: "#475569" },
    ],
    monthlyIntensity: [0.5, 0.5, 0.7, 0.8, 0.7, 0.1, 0, 0, 0.8, 1, 0.9, 0.6],
    trajectory: "직선예인(쌍동기화)",
  },
  "PT-S": {
    code: "PT-S",
    name: "2척식 저인망(부속선)",
    count: 323,
    allowedZones: ["2", "3"],
    color: "#3B82F6",
    icon: "⛵",
    speedProfile: [
      { label: "정박", range: [0, 0.5], typicalSpeed: 0.3, color: "#64748B" },
      { label: "보조", range: [1, 2.5], typicalSpeed: 1.5, color: "#F59E0B" },
      { label: "동기예인", range: [2.5, 4.5], typicalSpeed: 3.3, color: "#3B82F6", primary: true },
      { label: "추종", range: [4.5, 7], typicalSpeed: 5.5, color: "#8B5CF6" },
      { label: "고속", range: [7, 15], typicalSpeed: 8.3, color: "#475569" },
    ],
    monthlyIntensity: [0.5, 0.5, 0.7, 0.8, 0.7, 0.1, 0, 0, 0.8, 1, 0.9, 0.6],
    trajectory: "본선거울상",
  },
  GN: {
    code: "GN",
    name: "유망",
    count: 200,
    allowedZones: ["2", "3", "4"],
    color: "#059669",
    icon: "🪢",
    speedProfile: [
      { label: "정박", range: [0, 0.3], typicalSpeed: 0.2, color: "#64748B" },
      { label: "표류", range: [0.5, 2], typicalSpeed: 1, color: "#059669", primary: true },
      { label: "양망", range: [1, 3], typicalSpeed: 2, color: "#F59E0B" },
      { label: "투망", range: [2, 4], typicalSpeed: 3, color: "#EF4444" },
      { label: "항해", range: [5, 15], typicalSpeed: 7.5, color: "#475569" },
    ],
    monthlyIntensity: [0.6, 0.5, 0.7, 0.7, 0.6, 0.3, 0.2, 0.3, 0.9, 1, 0.9, 0.7],
    trajectory: "투망→표류→양망",
  },
  OT: {
    code: "OT",
    name: "1척식 저인망",
    count: 13,
    allowedZones: ["2", "3"],
    color: "#7C3AED",
    icon: "🚢",
    speedProfile: [
      { label: "정박", range: [0, 0.5], typicalSpeed: 0.3, color: "#64748B" },
      { label: "투양망", range: [1, 2], typicalSpeed: 1.5, color: "#F59E0B" },
      { label: "단독예인", range: [2.5, 5], typicalSpeed: 3.5, color: "#7C3AED", primary: true },
      { label: "항해", range: [5, 15], typicalSpeed: 8, color: "#475569" },
    ],
    monthlyIntensity: [0.5, 0.5, 0.7, 0.7, 0.6, 0.1, 0, 0, 0.8, 1, 0.8, 0.5],
    trajectory: "단독레이스트랙",
  },
  PS: {
    code: "PS",
    name: "위망/채낚기",
    count: 16,
    allowedZones: ["1", "2", "3", "4"],
    color: "#DC2626",
    icon: "🦑",
    speedProfile: [
      { label: "정박", range: [0, 0.3], typicalSpeed: 0.2, color: "#64748B" },
      { label: "위망", range: [0.3, 1.5], typicalSpeed: 0.5, color: "#DC2626", primary: true },
      { label: "채낚기", range: [0.3, 2], typicalSpeed: 0.8, color: "#F97316", primary: true },
      { label: "투양", range: [1.5, 3], typicalSpeed: 2, color: "#F59E0B" },
      { label: "항해", range: [5, 15], typicalSpeed: 8, color: "#475569" },
    ],
    monthlyIntensity: [0.6, 0.7, 0.8, 0.7, 0.4, 0.3, 0.5, 0.7, 0.9, 1, 0.8, 0.6],
    trajectory: "점군집/야간표류",
  },
  FC: {
    code: "FC",
    name: "운반선",
    count: 31,
    allowedZones: ["1", "2", "3", "4"],
    color: "#D97706",
    icon: "🚛",
    speedProfile: [
      { label: "정박", range: [0, 0.3], typicalSpeed: 0.2, color: "#64748B" },
      { label: "환적", range: [0.5, 2], typicalSpeed: 1, color: "#D97706", primary: true },
      { label: "저속", range: [3, 6], typicalSpeed: 4.5, color: "#8B5CF6" },
      { label: "고속", range: [6, 15], typicalSpeed: 9, color: "#475569" },
    ],
    monthlyIntensity: [0.4, 0.4, 0.6, 0.7, 0.5, 0.2, 0.1, 0.1, 0.8, 1, 0.9, 0.5],
    trajectory: "허브스포크순회",
  },
};

export const VESSEL_TOTAL_TARGET = Object.values(VESSEL_TYPES).reduce((sum, t) => sum + t.count, 0);

