// =============================================================================
// 🔧 ТИПЫ ДЛЯ СИСТЕМЫ СОЗДАНИЯ ПОСТАВОК РАСХОДНИКОВ СЕЛЛЕРА V2
// =============================================================================
// Адаптированные типы из основных типов для селлерской системы

import type {
  FulfillmentConsumableSupplier,
  FulfillmentConsumableProduct,
  SelectedFulfillmentConsumable,
  SupplyCreationInput as BaseSupplyCreationInput,
  CreateSupplyMutationResponse as BaseCreateSupplyMutationResponse,
} from './index'

// =============================================================================
// 📦 СЕЛЛЕРСКИЕ ТИПЫ (АДАПТАЦИЯ)
// =============================================================================

// Селлер использует те же типы поставщиков что и фулфилмент
export type SellerConsumableSupplier = FulfillmentConsumableSupplier
export type SellerConsumableProduct = FulfillmentConsumableProduct
export type SelectedSellerConsumable = SelectedFulfillmentConsumable

// =============================================================================
// 🆕 СПЕЦИФИЧНЫЕ ТИПЫ ДЛЯ СЕЛЛЕРА
// =============================================================================

// Статусы поставок селлера (5-статусная система)
export type SellerSupplyOrderStatus = 
  | 'PENDING'     // Ожидает одобрения поставщика
  | 'APPROVED'    // Одобрено поставщиком
  | 'SHIPPED'     // Отгружено
  | 'DELIVERED'   // Доставлено
  | 'COMPLETED'   // Завершено
  | 'CANCELLED'   // Отменено

// Данные для создания поставки селлера
export interface SellerSupplyCreationInput {
  fulfillmentCenterId: string          // куда доставлять (FULFILLMENT партнер)
  supplierId: string                   // от кого заказывать (WHOLESALE партнер)  
  logisticsPartnerId?: string          // кто везет (LOGIST партнер, опционально)
  requestedDeliveryDate: string        // когда нужно
  items: Array<{
    productId: string
    requestedQuantity: number
  }>
  notes?: string
}

// Response для создания поставки селлера
export interface CreateSellerSupplyMutationResponse {
  createSellerConsumableSupply: {
    success: boolean
    message: string
    supplyOrder?: {
      id: string
      status: SellerSupplyOrderStatus
      createdAt: string
    }
  }
}

// =============================================================================
// 🎯 ТИПЫ ДЛЯ ХУКОВ (АДАПТАЦИЯ)
// =============================================================================

export interface UseSellerSupplyCreationProps {
  selectedSupplier: SellerConsumableSupplier | null
  selectedFulfillment: SellerConsumableSupplier | null  // 🆕 Выбор фулфилмента
  selectedConsumables: SelectedSellerConsumable[]
  deliveryDate: string
  notes: string
  resetForm: () => void
}

export interface UseSellerSupplyCreationReturn {
  createSupply: () => Promise<void>
  isCreating: boolean
  error: string | null
}

export interface UseSellerSupplyFormReturn {
  selectedSupplier: SellerConsumableSupplier | null
  selectedFulfillment: SellerConsumableSupplier | null  // 🆕 Дополнительное поле
  selectedLogistics: SellerConsumableSupplier | null
  selectedConsumables: SelectedSellerConsumable[]
  searchQuery: string
  productSearchQuery: string
  deliveryDate: string
  notes: string
  setSelectedSupplier: (supplier: SellerConsumableSupplier | null) => void
  setSelectedFulfillment: (fulfillment: SellerConsumableSupplier | null) => void  // 🆕 Новый сеттер
  setSelectedLogistics: (logistics: SellerConsumableSupplier | null) => void
  setSelectedConsumables: (consumables: SelectedSellerConsumable[]) => void
  setSearchQuery: (query: string) => void
  setProductSearchQuery: (query: string) => void
  setDeliveryDate: (date: string) => void
  setNotes: (notes: string) => void
  resetForm: () => void
}

// =============================================================================
// 🎨 ТИПЫ UI КОМПОНЕНТОВ ДЛЯ СЕЛЛЕРА
// =============================================================================

export interface SellerSuppliersBlockProps {
  suppliers: SellerConsumableSupplier[]
  fulfillmentCenters: SellerConsumableSupplier[]        // 🆕 Список фулфилмент-центров
  filteredSuppliers: SellerConsumableSupplier[]
  filteredFulfillmentCenters: SellerConsumableSupplier[] // 🆕 Фильтрованные ФФ
  selectedSupplier: SellerConsumableSupplier | null
  selectedFulfillment: SellerConsumableSupplier | null  // 🆕 Выбранный фулфилмент
  searchQuery: string
  loading: boolean
  onSelectSupplier: (supplier: SellerConsumableSupplier | null) => void
  onSelectFulfillment: (fulfillment: SellerConsumableSupplier | null) => void // 🆕
  onSearchChange: (query: string) => void
}

export interface SellerShoppingCartBlockProps {
  selectedConsumables: SelectedSellerConsumable[]
  selectedFulfillment: SellerConsumableSupplier | null  // 🆕 Показ выбранного ФФ
  deliveryDate: string
  notes: string
  selectedLogistics: SellerConsumableSupplier | null
  logisticsPartners: SellerConsumableSupplier[]
  isCreatingSupply: boolean
  getTotalAmount: () => number
  getTotalItems: () => number
  formatCurrency: (amount: number) => string
  onUpdateQuantity: (productId: string, quantity: number) => void
  onSetDeliveryDate: (date: string) => void
  onSetNotes: (notes: string) => void
  onSetLogistics: (logistics: SellerConsumableSupplier | null) => void
  onCreateSupply: () => void
}

// =============================================================================
// 🔄 ТИПЫ ДЛЯ ПЕРЕКЛЮЧЕНИЯ СИСТЕМ
// =============================================================================

export interface SupplySystemConfig {
  type: 'FULFILLMENT' | 'SELLER'
  queries: {
    GET_MY_SUPPLIES: any
    CREATE_SUPPLY: any
    GET_COUNTERPARTIES: any
    GET_ORGANIZATION_PRODUCTS: any
  }
  components: {
    SuppliersBlock: React.ComponentType<any>
    ShoppingCartBlock: React.ComponentType<any>
  }
  hooks: {
    useSupplyCreation: any
    useSupplyForm: any
  }
}

// =============================================================================
// 🌐 ТИПЫ ДАННЫХ ЗАПРОСОВ ДЛЯ СЕЛЛЕРА
// =============================================================================

export interface SellerSuppliesData {
  mySellerConsumableSupplies: Array<{
    id: string
    status: SellerSupplyOrderStatus
    seller: { id: string; name: string; inn: string }
    fulfillmentCenter: { id: string; name: string; inn: string }
    supplier?: { id: string; name: string; inn: string }
    requestedDeliveryDate: string
    totalCostWithDelivery?: number
    items: Array<{
      id: string
      product: { id: string; name: string; article: string }
      requestedQuantity: number
      unitPrice: number
      totalPrice: number
    }>
    createdAt: string
  }>
}

export interface IncomingSellerSuppliesData {
  incomingSellerSupplies: Array<{
    id: string
    status: SellerSupplyOrderStatus
    seller: { id: string; name: string; inn: string }
    fulfillmentCenter: { id: string; name: string; inn: string }
    requestedDeliveryDate: string
    totalCostWithDelivery?: number
    createdAt: string
  }>
}