"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 CreateEquipmentTypeInputs = {
  id?: string | number;
  code: string;
  name: string;
  description?: string | undefined;
};

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