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

export interface WarehouseResult {
  id: number;
  code: string;
  name: string;
  description: string;
}

export interface WarehouseCombo {
  id: number;
  value: number;
  label: string;
}

export const fetchWarehouseList = cache(async () => {
  return serverFetchJson<WarehouseResult[]>(`${BASE_API_URL}/warehouse`, {
    next: { tags: ["warehouse"] },
  });
});

export const fetchWarehouseCombo = cache(async () => {
  return serverFetchJson<WarehouseCombo[]>(`${BASE_API_URL}/warehouse/combo`, {
    next: { tags: ["warehouseCombo"] },
  });
});
