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

export interface WarehouseResult {
  action: any;
  id: number;
  code: string;
  name: string;
  description: string;
  store_id?: string;
  warehouse?: string;
  area?: string;
  slot?: string;
  order?: string;
  stockTakeSection?: string;
  stockTakeSectionDescription?: 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"] },
  });
});
export interface StockTakeSectionInfo {
  id: string;
  stockTakeSection: string;
  stockTakeSectionDescription: string | null;
  storeId?: string | null;
  /** 倉庫區域（area），與盤點卡片上的 warehouseArea 對應 */
  warehouseArea?: string | null;
  warehouseCount: number;
}

export interface MissingStockTakeSectionIssueItem {
  id: number;
  code?: string | null;
  storeId?: string | null;
  warehouse?: string | null;
  area?: string | null;
  slot?: string | null;
  order?: string | null;
}

export interface MissingStockTakeSectionIssuesResponse {
  count: number;
  limit: number;
  items: MissingStockTakeSectionIssueItem[];
}