import { apiClient } from './client'

export interface BundleStats {
  total: number
  suggested: number
  accepted: number
  conversion_rate: number
  avg_discount: number
  period_total: number
  period_accepted: number
}

export interface WidgetTriggers {
  bundle_builder: number
  coupon: number
  product_card: number
}

export interface TopProduct {
  product_id: number
  product_name: string
  appearances: number
}

export interface WcAttribution {
  coupon_orders: number
  coupon_revenue: number
  available: boolean
}

export interface WooCommerceStatsResponse {
  success: boolean
  data: {
    bundles: BundleStats
    widget_triggers: WidgetTriggers
    top_products: TopProduct[]
    wc_attribution: WcAttribution
  }
}

export type StatsPeriod = '7d' | '30d' | '90d' | 'all'

export const woocommerceApi = {
  async getStats(language: string, period: StatsPeriod = '30d'): Promise<WooCommerceStatsResponse> {
    return apiClient.get<WooCommerceStatsResponse>('woocommerce/stats', { language, period })
  },
}
