import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";
import "server-only";

export interface BomWeightingScoreResult {
  id: number;
  code: string;
  name: string;
  range: number;
  weighting: number | string | { value?: number; [key: string]: any };
  remarks?: string;
}

export const preloadBomWeightingScores = () => {
  fetchBomWeightingScores();
};

export const fetchBomWeightingScores = cache(async () => {
  return serverFetchJson<BomWeightingScoreResult[]>(`${BASE_API_URL}/bomWeightingScores`, {
    next: { tags: ["bomWeightingScores"] },
  });
});
