import { api } from '@common/services/api';
import type { HnsAnalysisItem, CreateHnsAnalysisInput } from '@interfaces/hns/HnsInterface';

// ============================================================
// HNS 분석 API
// ============================================================


export async function fetchHnsAnalyses(params?: {
  status?: string;
  substance?: string;
  search?: string;
  acdntSn?: number;
}): Promise<HnsAnalysisItem[]> {
  const response = await api.get<HnsAnalysisItem[]>('/hns/analyses', { params });
  return response.data;
}

export async function fetchHnsAnalysis(sn: number): Promise<HnsAnalysisItem> {
  const response = await api.get<HnsAnalysisItem>(`/hns/analyses/${sn}`);
  return response.data;
}

export async function createHnsAnalysis(
  input: CreateHnsAnalysisInput,
): Promise<{ hnsAnlysSn: number }> {
  const response = await api.post<{ hnsAnlysSn: number }>('/hns/analyses', input);
  return response.data;
}

export async function saveHnsAnalysis(
  sn: number,
  data: {
    rsltData: Record<string, unknown>;
    execSttsCd?: string;
    riskCd?: string;
  },
): Promise<void> {
  await api.post(`/hns/analyses/${sn}/save`, data);
}

export async function deleteHnsAnalysis(sn: number): Promise<void> {
  await api.delete(`/hns/analyses/${sn}`);
}
