import { api } from '@common/services/api';

// ============================================================
// 구조 시나리오 API
// ============================================================

// === RESCUE_OPS ===
export interface RescueOpsItem {
  rescueOpsSn: number;
  acdntSn: number | null;
  opsCd: string;
  acdntTpCd: string;
  vesselNm: string;
  commanderNm: string | null;
  lon: number | null;
  lat: number | null;
  locDc: string | null;
  depthM: number | null;
  currentDc: string | null;
  gmM: number | null;
  listDeg: number | null;
  trimM: number | null;
  buoyancyPct: number | null;
  oilRateLpm: number | null;
  bmRatioPct: number | null;
  totalCrew: number | null;
  survivors: number | null;
  missing: number | null;
  hydroData: Record<string, unknown> | null;
  gmdssData: Record<string, unknown> | null;
  sttsCd: string;
  regDtm: string;
}

// === RESCUE_SCENARIO ===
export interface RescueScenarioItem {
  scenarioSn: number;
  rescueOpsSn: number;
  timeStep: string;
  scenarioDtm: string | null;
  svrtCd: string; // CRITICAL/HIGH/MEDIUM/RESOLVED
  gmM: number | null;
  listDeg: number | null;
  trimM: number | null;
  buoyancyPct: number | null;
  oilRateLpm: number | null;
  bmRatioPct: number | null;
  description: string | null;
  compartments: Array<{ name: string; status: string; color: string }> | null;
  assessment: Array<{ label: string; value: string; color: string }> | null;
  actions: Array<{ time: string; text: string; color: string }> | null;
  sortOrd: number;
}

export async function fetchRescueOps(params?: {
  sttsCd?: string;
  acdntTpCd?: string;
  search?: string;
}): Promise<RescueOpsItem[]> {
  const response = await api.get<RescueOpsItem[]>('/rescue/ops', { params });
  return response.data;
}

export async function fetchRescueOpsDetail(sn: number): Promise<RescueOpsItem> {
  const response = await api.get<RescueOpsItem>(`/rescue/ops/${sn}`);
  return response.data;
}

export async function fetchRescueScenarios(rescueOpsSn: number): Promise<RescueScenarioItem[]> {
  const response = await api.get<RescueScenarioItem[]>(`/rescue/ops/${rescueOpsSn}/scenarios`);
  return response.data;
}
