"server=only";

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

export interface Operator {
  id: number;
  name: string;
  username: string;
}

export interface Machine {
  id: number;
  name: string;
  code: string;
  qrCode: string;
}

export interface JoDetail {
  id: number;
  code: string;
  name: string;
  reqQty: number;
  uom: string;
  pickLines: JoDetailPickLine[];
  status: string;
  planStart: number[];
  planEnd: number[];
  type: string;
}

export interface JoDetailPickLine {
  id: number;
  code: string;
  name: string;
  lotNo: string;
  reqQty: number;
  uom: string;
  status: string;
}

export const fetchJoDetail = cache(async (id: number) => {
  return serverFetchJson<JoDetail>(`${BASE_API_URL}/jo/detail/${id}`,
  {
    method: "GET",
    headers: { "Content-Type": "application/json"},
    next: {
      tags: ["jo"]
    }
  })
})