"use client";

import axiosInstance from "@/app/(main)/axios/axiosInstance";
import { NEXT_PUBLIC_API_URL } from "@/config/api";
import { BomWeightingScoreResult } from "./index";

export interface UpdateBomWeightingScoreInputs {
  id: number;
  name: string;
  range: number;
  weighting: number;
  remarks?: string;
}

export const fetchBomWeightingScoresClient = async (): Promise<BomWeightingScoreResult[]> => {
  const response = await axiosInstance.get<BomWeightingScoreResult[]>(
    `${NEXT_PUBLIC_API_URL}/bomWeightingScores`
  );
  return response.data;
};

export const updateBomWeightingScoreClient = async (
  data: UpdateBomWeightingScoreInputs
): Promise<BomWeightingScoreResult> => {
  const response = await axiosInstance.put<BomWeightingScoreResult>(
    `${NEXT_PUBLIC_API_URL}/bomWeightingScores/${data.id}`,
    data
  );
  return response.data;
};
