export type WarehouseType = 'SELF' | 'THIRD_PARTY' | 'VIRTUAL';
export type StockStatus = 'AVAILABLE' | 'RESERVED' | 'DAMAGED' | 'EXPIRED' | 'IN_TRANSIT';
export type MappingType = 'ONE_TO_ONE' | 'ONE_TO_MANY' | 'COMBO' | 'BUNDLE';

export interface Warehouse {
  id: string;
  tenant_id: string;
  name: string;
  code: string;
  type: WarehouseType;
  address: string;
  contact_person: string;
  contact_phone: string;
  capacity: number;
  used_capacity: number;
  status: 'ACTIVE' | 'INACTIVE' | 'MAINTENANCE';
  priority: number;
  created_at: string;
  updated_at: string;
}

export interface WarehouseSku {
  id: string;
  warehouse_id: string;
  sku_code: string;
  sku_name: string;
  barcode?: string;
  category: string;
  specifications: Record<string, string>;
  unit: string;
  weight_kg: number;
  volume_m3: number;
  shelf_location: string;
  safety_stock: number;
  max_stock: number;
  created_at: string;
  updated_at: string;
}

export interface WarehouseStock {
  id: string;
  warehouse_id: string;
  warehouse_sku_id: string;
  sku_code: string;
  quantity: number;
  available_quantity: number;
  reserved_quantity: number;
  damaged_quantity: number;
  in_transit_quantity: number;
  status: StockStatus;
  batch_number?: string;
  expiry_date?: string;
  last_inbound_at?: string;
  last_outbound_at?: string;
  created_at: string;
  updated_at: string;
}

export interface SalesSku {
  id: string;
  tenant_id: string;
  shop_id: string;
  sku_code: string;
  sku_name: string;
  product_id: string;
  product_name: string;
  platform: string;
  platform_sku_id?: string;
  price: number;
  cost_price: number;
  status: 'ACTIVE' | 'INACTIVE' | 'DISCONTINUED';
  created_at: string;
  updated_at: string;
}

export interface SkuMapping {
  id: string;
  tenant_id: string;
  sales_sku_id: string;
  sales_sku_code: string;
  mapping_type: MappingType;
  warehouse_items: WarehouseMappingItem[];
  is_active: boolean;
  priority: number;
  created_at: string;
  updated_at: string;
}

export interface WarehouseMappingItem {
  warehouse_sku_id: string;
  warehouse_sku_code: string;
  quantity: number;
  warehouse_id: string;
}

export interface StockMovement {
  id: string;
  tenant_id: string;
  warehouse_id: string;
  warehouse_sku_id: string;
  sku_code: string;
  movement_type: 'INBOUND' | 'OUTBOUND' | 'TRANSFER' | 'ADJUSTMENT' | 'RESERVE' | 'RELEASE';
  quantity: number;
  before_quantity: number;
  after_quantity: number;
  reference_type?: 'ORDER' | 'PURCHASE' | 'RETURN' | 'ADJUSTMENT';
  reference_id?: string;
  order_id?: string;
  order_item_id?: string;
  operator: string;
  remark?: string;
  created_at: string;
}

export interface StockReservation {
  id: string;
  tenant_id: string;
  warehouse_id: string;
  warehouse_sku_id: string;
  sku_code: string;
  order_id: string;
  order_item_id: string;
  sales_sku_code: string;
  quantity: number;
  status: 'PENDING' | 'CONFIRMED' | 'RELEASED' | 'FULFILLED';
  reserved_at: string;
  expires_at: string;
  released_at?: string;
  created_at: string;
  updated_at: string;
}

export interface InventoryAlert {
  id: string;
  tenant_id: string;
  warehouse_id: string;
  warehouse_sku_id: string;
  sku_code: string;
  alert_type: 'LOW_STOCK' | 'OVERSTOCK' | 'EXPIRING' | 'OUT_OF_STOCK';
  current_quantity: number;
  threshold: number;
  message: string;
  status: 'ACTIVE' | 'RESOLVED' | 'IGNORED';
  created_at: string;
  resolved_at?: string;
}

export interface StockAvailability {
  sales_sku_code: string;
  total_available: number;
  total_reserved: number;
  total_in_transit: number;
  warehouse_breakdown: {
    warehouse_id: string;
    warehouse_name: string;
    available: number;
    reserved: number;
  }[];
  can_fulfill: boolean;
  earliest_available_date?: string;
}

export interface OrderFulfillmentPlan {
  order_id: string;
  items: OrderFulfillmentItem[];
  total_warehouses: number;
  estimated_ship_date: string;
  fulfillment_strategy: 'SINGLE_WAREHOUSE' | 'MULTI_WAREHOUSE' | 'PARTIAL';
}

export interface OrderFulfillmentItem {
  order_item_id: string;
  sales_sku_code: string;
  quantity: number;
  warehouse_allocations: {
    warehouse_id: string;
    warehouse_name: string;
    warehouse_sku_code: string;
    quantity: number;
    shelf_location: string;
  }[];
}
