"use client"; import axiosInstance from "@/app/(main)/axios/axiosInstance"; import { NEXT_PUBLIC_API_URL } from "@/config/api"; import type { BomFormatCheckResponse, BomUploadResponse, ImportBomItemPayload, BomCombo, BomDetailResponse, EditBomRequest, } from "./index"; export async function uploadBomFiles( files: File[] ): Promise { const formData = new FormData(); files.forEach((f) => formData.append("files", f, f.name)); const response = await axiosInstance.post( `${NEXT_PUBLIC_API_URL}/bom/import-bom/upload`, formData, { transformRequest: [ (data: unknown, headers?: Record) => { if (data instanceof FormData && headers && "Content-Type" in headers) { delete headers["Content-Type"]; } return data; }, ], } ); return response.data; } export async function checkBomFormat( batchId: string ): Promise { const response = await axiosInstance.post( `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-check`, { batchId } ); return response.data; } export async function downloadBomFormatIssueLog( batchId: string, issueLogFileId: string ): Promise { const response = await axiosInstance.get( `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-issue-log`, { params: { batchId, issueLogFileId }, responseType: "blob", } ); return response.data as Blob; } export async function importBom( batchId: string, items: ImportBomItemPayload[] ): Promise { const response = await axiosInstance.post( `${NEXT_PUBLIC_API_URL}/bom/import-bom`, { batchId, items }, { responseType: "blob" } ); return response.data as Blob; } import type { BomScoreResult } from "./index"; export const fetchBomScoresClient = async (): Promise => { const response = await axiosInstance.get( `${NEXT_PUBLIC_API_URL}/bom/scores`, ); return response.data; }; export async function fetchBomComboClient(): Promise { const response = await axiosInstance.get( `${NEXT_PUBLIC_API_URL}/bom/combo` ); return response.data; } export async function fetchBomDetailClient(id: number): Promise { const response = await axiosInstance.get( `${NEXT_PUBLIC_API_URL}/bom/${id}/detail` ); return response.data; } export async function editBomClient( id: number, request: EditBomRequest, ): Promise { const response = await axiosInstance.put( `${NEXT_PUBLIC_API_URL}/bom/${id}`, request, ); return response.data; } export type BomExcelCheckProgress = { batchId: string; totalFiles: number; processedFiles: number; currentFileName: string | null; lastUpdateTime: number; }; export async function getBomFormatProgress( batchId: string ): Promise { const response = await axiosInstance.get( `${NEXT_PUBLIC_API_URL}/bom/import-bom/format-check/progress`, { params: { batchId } } ); return response.data; }