import "server-only";

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

export interface StockIssueResult {
  action: any;
  id: number;
  itemId: number;
  itemCode: string;
  itemDescription: string;
  lotId: number;
  lotNo: string;
  storeLocation: string;
  requiredQty: number;
  badItemQty: number;
  issueRemark: string;
  pickerName: string;
  handleStatus: string;
  handleDate: string;
  handledBy: number;
}

export const PreloadList = () => {
  fetchList();
};

export const fetchList = cache(async () => {
  return serverFetchJson<StockIssueResult[]>(`${BASE_API_URL}/pickExecution/badItemList`, {
    next: { tags: ["Bad Item List"] },
  });
});
