"use server";

import { cache } from 'react';
import { Pageable, serverFetchBlob, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
//import { JobOrder, JoStatus, Machine, Operator } from ".";
import { BASE_API_URL } from "@/config/api";
import { revalidateTag } from "next/cache";
import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
import { FileResponse } from "@/app/api/pdf/actions"; 
export interface GetBagInfoResponse {
    id: number;
    bagId: number;
    bagName: string;
    lotId: number;
    lotNo: string;
    stockOutLineId: number;
    code: string;
    balanceQty: number;
}
export const getBagInfo = cache(async () => {
    return serverFetchJson<GetBagInfoResponse[]>(
      `${BASE_API_URL}/bag/bagInfo`,
      {
        method: "GET",
        next: { tags: ["bagInfo"] },
      }
    );
  });

  export interface CreateJoBagConsumptionRequest {
    bagId: number;
    bagLotLineId: number;
    jobId: number;
    //startQty: number;
    consumedQty: number;
    scrapQty: number;
  }
  export const createJoBagConsumption = cache(async (request: CreateJoBagConsumptionRequest) => {
    return serverFetchJson<any>(
      `${BASE_API_URL}/bag/createJoBagConsumption`,
      {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(request),
      }
    );
  });