// Типы для FulfillmentWarehouseDashboard модульной архитектуры

// === ОСНОВНЫЕ ТИПЫ ДАННЫХ ===

export interface ProductVariant {
  id: string
  name: string // Размер, характеристика, вариант упаковки
  // Места и количества для каждого типа на уровне варианта
  productPlace?: string
  productQuantity: number
  goodsPlace?: string
  goodsQuantity: number
  defectsPlace?: string
  defectsQuantity: number
  sellerSuppliesPlace?: string
  sellerSuppliesQuantity: number
  sellerSuppliesOwners?: string[] // Владельцы расходников
  pvzReturnsPlace?: string
  pvzReturnsQuantity: number
}

export interface ProductItem {
  id: string
  name: string
  article: string
  // Места и количества для каждого типа
  productPlace?: string
  productQuantity: number
  goodsPlace?: string
  goodsQuantity: number
  defectsPlace?: string
  defectsQuantity: number
  sellerSuppliesPlace?: string
  sellerSuppliesQuantity: number
  sellerSuppliesOwners?: string[] // Владельцы расходников
  pvzReturnsPlace?: string
  pvzReturnsQuantity: number
  // Третий уровень - варианты товара
  variants?: ProductVariant[]
}

export interface StoreData {
  id: string
  name: string
  logo?: string
  avatar?: string // Аватар пользователя организации
  products: number
  goods: number
  defects: number
  sellerSupplies: number
  pvzReturns: number
  // Изменения за сутки
  productsChange: number
  goodsChange: number
  defectsChange: number
  sellerSuppliesChange: number
  pvzReturnsChange: number
  // Детализация по товарам
  items: ProductItem[]
}

export interface WarehouseStats {
  products: { current: number; change: number }
  goods: { current: number; change: number }
  defects: { current: number; change: number }
  pvzReturns: { current: number; change: number }
  fulfillmentSupplies: { current: number; change: number }
  sellerSupplies: { current: number; change: number }
}

export interface Supply {
  id: string
  name: string
  description?: string
  price: number
  quantity: number
  unit: string
  category: string
  status: string
  date: string
  supplier: string
  minStock: number
  currentStock: number
}

export interface SupplyOrder {
  id: string
  status: 'PENDING' | 'CONFIRMED' | 'IN_TRANSIT' | 'DELIVERED' | 'CANCELLED'
  deliveryDate: string
  totalAmount: number
  totalItems: number
  partner: {
    id: string
    name: string
    fullName: string
  }
  items: Array<{
    id: string
    quantity: number
    product: {
      id: string
      name: string
      article: string
    }
  }>
}

// === ТИПЫ ДЛЯ КОМПОНЕНТОВ ===

export interface TotalsData {
  products: number
  goods: number  
  defects: number
  sellerSupplies: number
  pvzReturns: number
  // Изменения за сутки
  productsChange: number
  goodsChange: number
  defectsChange: number
  sellerSuppliesChange: number
  pvzReturnsChange: number
}

export type StoreDataField = keyof Pick<StoreData, 'name' | 'products' | 'goods' | 'defects' | 'sellerSupplies' | 'pvzReturns'>

// === ПРОПСЫ ДЛЯ БЛОКОВ ===

// Интерфейсы перенесены в секцию "ПРОПСЫ БЛОКОВ" ниже, чтобы избежать дублирования

// === ПРОПСЫ ДЛЯ ХУКОВ ===

export interface UseWarehouseDataReturn {
  // Данные
  counterpartiesData: any
  ordersData: any
  warehouseData: any
  sellerSuppliesData: any
  fulfillmentSuppliesData: any
  warehouseStatsData: any
  
  // Состояния
  loading: boolean
  error: string | null
  
  // Действия
  refetchAll: () => Promise<void>
  refetchCounterparties: () => Promise<any>
  refetchOrders: () => Promise<any>
  refetchWarehouse: () => Promise<any>
  refetchSellerSupplies: () => Promise<any>
  refetchFulfillmentSupplies: () => Promise<any>
  refetchStats: () => Promise<any>
}

export interface UseWarehouseStatsReturn {
  warehouseStats: WarehouseStats
  suppliesReceivedToday: number
  productsReceivedToday: number
  isStatsLoading: boolean
}

export interface UseTableStateReturn {
  // Состояния
  searchTerm: string
  sortField: StoreDataField
  sortOrder: 'asc' | 'desc' 
  expandedStores: Set<string>
  expandedItems: Set<string>
  showAdditionalValues: boolean
  
  // Действия
  setSearchTerm: (term: string) => void
  handleSort: (field: StoreDataField) => void
  toggleStore: (storeId: string) => void
  toggleItem: (itemId: string) => void
  toggleAdditionalValues: () => void
}

export interface UseStoreDataReturn {
  storeData: StoreData[]
  filteredAndSortedStores: StoreData[]
  totals: TotalsData
  isProcessing: boolean
}

// === ПРОПСЫ БЛОКОВ ===

export interface WarehouseStatsBlockProps {
  warehouseStats: WarehouseStats
  warehouseStatsData: any  // GraphQL данные для percentChange
  isStatsLoading: boolean
}

export interface TableHeadersBlockProps {
  searchTerm: string
  sortField: StoreDataField
  sortOrder: 'asc' | 'desc'
  showAdditionalValues: boolean
  onSearchChange: (term: string) => void
  onSort: (field: StoreDataField) => void
  onToggleAdditionalValues: () => void
}

export interface SummaryRowBlockProps {
  totals: TotalsData
  showAdditionalValues: boolean
}

export interface StoreDataTableBlockProps {
  storeData: StoreData[]
  expandedStores: Set<string>
  expandedItems: Set<string>
  showAdditionalValues: boolean
  onToggleStore: (storeId: string) => void
  onToggleItem: (itemId: string) => void
}

// === ОСНОВНЫЕ ПРОПСЫ КОМПОНЕНТА ===

export interface FulfillmentWarehouseDashboardProps {
  // Компонент пока без внешних пропсов
  // В будущем можно добавить initialFilters, onNavigate и т.д.
}