import { cache } from "react";
import "server-only";
// import { serverFetchJson } from "@/app/utils/fetchUtil";
// import { BASE_API_URL } from "@/config/api";
import { serverFetchJson } from "../../../utils/fetchUtil";
import { BASE_API_URL } from "../../../../config/api";
export { default } from "../../../../components/CreateEquipment/CreateEquipment";
// import { TypeInputs, UomInputs, WeightUnitInputs } from "./actions";

export type EquipmentResult = {
  id: string | number;
  code: string;
  name: string;
  description: string | undefined;
  equipmentTypeId: string | number | undefined;
  equipmentCode?: string;
  action?: any;
  repairAndMaintenanceStatus?: boolean | number;
  latestRepairAndMaintenanceDate?: string | Date;
  lastRepairAndMaintenanceDate?: string | Date;
  repairAndMaintenanceRemarks?: string;
};

export type Result = {
  equipment: EquipmentResult;
};
export const fetchAllEquipments = cache(async () => {
  return serverFetchJson<EquipmentResult[]>(`${BASE_API_URL}/Equipment`, {
    next: { tags: ["equipments"] },
  });
});

export const fetchEquipment = cache(async (id: number) => {
  return serverFetchJson<EquipmentResult>(
    `${BASE_API_URL}/Equipment/details/${id}`,
    {
      next: { tags: ["equipments"] },
    },
  );
});
