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

// Основные интерфейсы для внешней рекламы
export interface ExternalAd {
  id: string
  name: string
  url: string
  cost: number
  clicks?: number
}

export interface ProductAdvertising {
  wbCampaigns: {
    campaignId: number
    views: number
    clicks: number
    cost: number
    orders: number
  }[]
  externalAds: ExternalAd[]
}

export interface ProductData {
  nmId: number
  name: string
  totalViews: number
  totalClicks: number
  totalCost: number
  totalOrders: number
  totalRevenue: number
  advertising: ProductAdvertising
}

export interface DailyAdvertisingData {
  date: string
  totalSum: number
  totalOrders: number
  totalRevenue: number
  products: ProductData[]
}

// Интерфейсы для кампаний
export interface CampaignStats {
  campaignId: number
  views: number
  clicks: number
  cost: number
  orders: number
}

export interface CampaignListItem {
  advertId: number
  name: string
  type: number
  status: number
  dailyBudget: number
}

export interface CampaignGroup {
  advert_list: CampaignListItem[]
}

// Интерфейсы для ссылок-кликеров
export interface GeneratedLink {
  id: string
  adId: string
  adName: string
  targetUrl: string
  trackingUrl: string
  clicks?: number
  lastClickDate?: string
}

// Пропсы для основного компонента
export interface CampaignStatsProps {
  selectedPeriod: string
  useCustomDates: boolean
  startDate: string
  endDate: string
  getCachedData?: () => any
  setCachedData?: (data: any) => void
  isLoadingData?: boolean
  setIsLoadingData?: (loading: boolean) => void
}

// Пропсы для блоков
export interface CampaignSelectorBlockProps {
  onCampaignsSelected: (ids: number[]) => void
  selectedCampaigns: number[]
  loading: boolean
}

export interface SpendingChartBlockProps {
  dailyData: DailyAdvertisingData[]
  showWbAds: boolean
  showExternalAds: boolean
  onToggleWbAds: (show: boolean) => void
  onToggleExternalAds: (show: boolean) => void
}

export interface TableBlockProps {
  dailyData: DailyAdvertisingData[]
  productPhotos: Map<number, string>
  expandedDays: Set<string>
  expandedProducts: Set<string>
  expandedCampaigns: Set<number>
  showAddForm: string | null
  newExternalAd: {
    name: string
    url: string
    cost: string
  }
  generatedLinksData: Record<string, GeneratedLink[]>
  onToggleDay: (date: string) => void
  onToggleProduct: (key: string) => void
  onToggleCampaign: (campaignId: number) => void
  onShowAddForm: (key: string | null) => void
  onUpdateNewExternalAd: (ad: { name: string; url: string; cost: string }) => void
  onAddExternalAd: (productKey: string) => void
  onRemoveExternalAd: (adId: string) => void
  onUpdateExternalAd: (adId: string, field: string, value: string) => void
  onGenerateLink: (adId: string, adName: string, targetUrl: string) => void
  onCopyLink: (url: string) => void
}

export interface ErrorDisplayBlockProps {
  error?: {
    message: string
    graphQLErrors?: Array<{ message: string }>
  }
}

export interface EmptyStateBlockProps {
  isLoading: boolean
  hasData: boolean
}

// Хуки интерфейсы
export interface UseCampaignDataReturn {
  campaignStats: CampaignStats[]
  loading: boolean
  error?: any
  handleCampaignsSelected: (campaignIds: number[]) => void
  fetchingRef: React.MutableRefObject<boolean>
  loadKey: number
}

export interface UseExternalAdsManagementReturn {
  externalAdsData: any
  externalAdsLoading: boolean
  externalAdsError?: any
  handleAddExternalAd: (productKey: string, newAd: { name: string; url: string; cost: string }) => void
  handleRemoveExternalAd: (adId: string) => void
  handleUpdateExternalAd: (adId: string, field: string, value: string) => void
}

export interface UseGeneratedLinksReturn {
  generatedLinksData: Record<string, GeneratedLink[]>
  handleGenerateLink: (adId: string, adName: string, targetUrl: string) => void
  handleCopyLink: (url: string) => void
  loadClickStatistics: () => Promise<void>
}

export interface UseProductPhotosReturn {
  productPhotos: Map<number, string>
  loadProductPhotos: (nmIds: number[]) => Promise<void>
}

export interface UseDataProcessingReturn {
  dailyData: DailyAdvertisingData[]
  convertCampaignDataToDailyData: (campaignStats: CampaignStats[], externalAdsData: any) => void
  getDateRange: (selectedPeriod: string, useCustomDates: boolean, startDate: string, endDate: string) => { startDate: Date; endDate: Date }
}

export interface UseUIStateReturn {
  expandedDays: Set<string>
  expandedProducts: Set<string>
  expandedCampaigns: Set<number>
  showWbAds: boolean
  showExternalAds: boolean
  showAddForm: string | null
  newExternalAd: {
    name: string
    url: string
    cost: string
  }
  onToggleDay: (date: string) => void
  onToggleProduct: (key: string) => void
  onToggleCampaign: (campaignId: number) => void
  onToggleWbAds: (show: boolean) => void
  onToggleExternalAds: (show: boolean) => void
  onShowAddForm: (key: string | null) => void
  onUpdateNewExternalAd: (ad: { name: string; url: string; cost: string }) => void
}

// Утилитарные типы
export interface DateRange {
  startDate: Date
  endDate: Date
}

export interface ChartDataPoint {
  date: string
  wbSum: number
  externalSum: number
  totalSum: number
}

export interface FormattingUtils {
  formatCurrency: (value: number) => string
  formatNumber: (value: number) => string
  formatPercent: (value: number) => string
}