import request from '@/config/axios'

// ERP 采购全局统计 VO
export interface ErpPurchaseSummaryRespVO {
  todayPrice: number // 今日采购金额
  yesterdayPrice: number // 昨日采购金额
  monthPrice: number // 本月采购金额
  yearPrice: number // 今年采购金额
}

// ERP 采购时间段统计 VO
export interface ErpPurchaseTimeSummaryRespVO {
  time: string // 时间
  price: number // 采购金额
}

// ERP 采购趋势统计 VO
export interface ErpPurchaseTrendRespVO {
  time: string // 时间
  price: number // 采购金额
  count: number // 采购数量
}

// ERP 采购产品排行 VO
export interface ErpPurchaseProductRankRespVO {
  productId: number // 产品编号
  productName: string // 产品名称
  count: number // 采购数量
  price: number // 采购金额
}

// ERP 采购供应商排行 VO
export interface ErpPurchaseSupplierRankRespVO {
  supplierId: number // 供应商编号
  supplierName: string // 供应商名称
  count: number // 采购数量
  price: number // 采购金额
}

// ERP 采购统计 API
export const PurchaseStatisticsApi = {
  // 获得采购统计
  getPurchaseSummary: async (): Promise<ErpPurchaseSummaryRespVO> => {
    return await request.get({ url: `/erp/purchase-statistics/summary` })
  },

  // 获得采购时间段统计
  getPurchaseTimeSummary: async (): Promise<ErpPurchaseTimeSummaryRespVO[]> => {
    return await request.get({ url: `/erp/purchase-statistics/time-summary` })
  },

  // 获得采购趋势统计（按周）
  getPurchaseTrendByWeek: async (count: number = 12): Promise<ErpPurchaseTrendRespVO[]> => {
    return await request.get({ url: `/erp/purchase-statistics/trend-by-week`, params: { count } })
  },

  // 获得采购趋势统计（按月）
  getPurchaseTrendByMonth: async (count: number = 12): Promise<ErpPurchaseTrendRespVO[]> => {
    return await request.get({ url: `/erp/purchase-statistics/trend-by-month`, params: { count } })
  },

  // 获得采购产品排行
  getPurchaseProductRank: async (beginTime: string, endTime: string, limit: number = 10): Promise<ErpPurchaseProductRankRespVO[]> => {
    return await request.get({ 
      url: `/erp/purchase-statistics/product-rank`, 
      params: { beginTime, endTime, limit } 
    })
  },

  // 获得采购供应商排行
  getPurchaseSupplierRank: async (beginTime: string, endTime: string, limit: number = 10): Promise<ErpPurchaseSupplierRankRespVO[]> => {
    return await request.get({ 
      url: `/erp/purchase-statistics/supplier-rank`, 
      params: { beginTime, endTime, limit } 
    })
  },

  // AI分析采购统计数据
  analyzeWithAI: async (analysisData: any) => {
    return await request.post({ url: `/erp/purchase-statistics/ai-analysis`, data: analysisData })
  }
}
