/**
 * 倉庫相關型別定義
 */

export type WarehouseType = "中央倉庫" | "門市";

/**
 * 門市資訊
 */
export interface Store {
  id: string;
  name: string;
  address: string;
}

export interface Warehouse {
  id: string;
  name: string;
  address: string;
  manager: string;
  phone: string;
  description: string;
  createdAt: string;
  type: WarehouseType;
  storeId?: string; // 綁定的門市 ID (僅當 type 為 "門市" 時使用)
  storeName?: string; // 綁定的門市名稱 (僅當 type 為 "門市" 時使用)
}

export interface WarehouseInventory {
  warehouseId: string;
  productId: string;
  productName: string;
  quantity: number;
  batchNumber: string;
  expiryDate: string;
  lastInboundDate?: string;
  lastOutboundDate?: string;
}

export type TransferOrderStatus = "待處理" | "處理中" | "已完成" | "已取消";

export interface TransferOrder {
  id: string;
  orderNumber: string;
  sourceWarehouseId: string;
  sourceWarehouseName: string;
  targetWarehouseId: string;
  targetWarehouseName: string;
  productId: string;
  productName: string;
  batchNumber: string;
  quantity: number;
  transferDate: string;
  status: TransferOrderStatus;
  notes?: string;
  createdAt: string;
}

export interface Product {
  id: string;
  name: string;
  type: "原物料" | "半成品" | "成品";
}

export interface WarehouseStats {
  totalQuantity: number;
  lowStockCount: number;
  replenishmentNeeded: number;
}

/**
 * 安全庫存設定
 */
export interface SafetyStockSetting {
  id: string;
  warehouseId: string;
  productId: string;
  productName: string;
  productType: "原物料" | "半成品" | "成品";
  safetyStock: number;
  createdAt: string;
  updatedAt: string;
}

/**
 * 安全庫存狀態
 */
export type SafetyStockStatus = "正常" | "接近" | "低於";

/**
 * 入庫原因類型
 */
export type InboundReason =
  | "期初建檔"
  | "盤點調整"
  | "實際入庫未走採購流程"
  | "生產加工成品入庫"
  | "其他";

/**
 * 庫存異動類型
 */
export type TransactionType =
  | "手動入庫"
  | "手動出庫"
  | "撥補入庫"
  | "撥補出庫"
  | "盤點調整"
  | "其他";

/**
 * 庫存異動記錄
 */
export interface InventoryTransaction {
  id: string;
  warehouseId: string;
  warehouseName: string;
  productId: string;
  productName: string;
  batchNumber: string;
  quantity: number; // 正數為入庫，負數為出庫
  transactionType: TransactionType;
  reason?: string;
  notes?: string;
  expiryDate?: string;
  operatorName?: string;
  createdAt: string;
}

/**
 * 入庫明細項目
 */
export interface InboundItem {
  tempId: string; // 臨時ID，用於表單編輯
  productId: string;
  productName: string;
  quantity: number;
  unit: string;
  expiryDate: string;
  batchNumber: string;
  autoGeneratedBatch: boolean; // 是否為系統自動生成的批號
}

/**
 * 入庫記錄
 */
export interface InboundRecord {
  id: string;
  warehouseId: string;
  warehouseName: string;
  inboundDate: string;
  reason: InboundReason;
  notes?: string;
  items: InboundItem[];
  operatorName?: string;
  createdAt: string;
}