"use server";
import {
  ServerFetchError,
  serverFetchJson,
  serverFetchWithNoContent,
} from "@/app/utils/fetchUtil";
import { revalidateTag } from "next/cache";
import { BASE_API_URL } from "@/config/api";
import { CreateEquipmentTypeResponse } from "../../utils";

// export type TypeInputs = {
//   id: number;
//   name: string
// }
// export type UomInputs = {
//   uom: string
// }
// export type WeightUnitInputs = {
//   weightUnit: string
//   conversion: number
// }

export type CreateEquipmentInputs = {
  id?: string | number;
  code: string;
  name: string;
  description?: string | undefined;
  equipmentTypeId?: string | number | undefined;
};

export const saveEquipment = async (data: CreateEquipmentInputs) => {
  // try {
  const equipment = await serverFetchJson<
    CreateEquipmentTypeResponse<CreateEquipmentInputs>
  >(`${BASE_API_URL}/Equipment/save`, {
    method: "POST",
    body: JSON.stringify(data),
    headers: { "Content-Type": "application/json" },
  });
  revalidateTag("EquipmentType");
  return equipment;
};
