import request from '@/config/axios'

export interface SupplierEvaluationVO {
  id?: number
  supplierId: number
  supplierName?: string
  purchaseOrderId: number
  orderNo?: string
  qualityScore: number
  serviceScore: number
  priceScore: number
  deliveryScore: number
  totalScore: number
  remark?: string
  createTime?: Date
  creator?: string
  creatorName?: string
}

export interface SupplierEvaluationPageReqVO {
  pageNo?: number
  pageSize?: number
  supplierId?: number
  purchaseOrderId?: number
  purchaseOrderNo?: string
  createTime?: Date[]
  minScore?: number
  maxScore?: number
  creator?: number
}

// ERP 供应商评价 API
export const SupplierEvaluationApi = {
  // 查询供应商评价分页
  getSupplierEvaluationPage: async (params: SupplierEvaluationPageReqVO) => {
    return await request.get({ url: `/erp/supplier-evaluation/page`, params })
  },

  // 查询供应商评价详情
  getSupplierEvaluation: async (id: number) => {
    return await request.get({ url: `/erp/supplier-evaluation/get?id=` + id })
  },

  // 新增供应商评价
  createSupplierEvaluation: async (data: SupplierEvaluationVO) => {
    return await request.post({ url: `/erp/supplier-evaluation/create`, data })
  },

  // 修改供应商评价
  updateSupplierEvaluation: async (data: SupplierEvaluationVO) => {
    return await request.put({ url: `/erp/supplier-evaluation/update`, data })
  },

  // 删除供应商评价
  deleteSupplierEvaluation: async (id: number) => {
    return await request.delete({ url: `/erp/supplier-evaluation/delete?id=` + id })
  },

  // 导出供应商评价 Excel
  exportSupplierEvaluation: async (params: any) => {
    return await request.download({ url: `/erp/supplier-evaluation/export-excel`, params })
  },

  // 查询供应商的平均评分
  getSupplierAverageScore: async (supplierId: number) => {
    return await request.get({ url: `/erp/supplier-evaluation/average-score?supplierId=` + supplierId })
  },

  // 查询供应商评价统计
  getSupplierEvaluationStats: async (supplierId: number) => {
    return await request.get({ url: `/erp/supplier-evaluation/stats?supplierId=` + supplierId })
  },

  // 获取供应商评价汇总列表
  getSupplierSummaryList: async (params?: any) => {
    return await request.get({ url: `/erp/supplier-evaluation/supplier-summary`, params })
  },

  // 获取供应商评价历史
  getSupplierEvaluationHistory: async (supplierId: number, params?: any) => {
    return await request.get({ url: `/erp/supplier-evaluation/supplier/${supplierId}/history`, params })
  },

  // AI分析供应商评价数据
  analyzeWithAI: async (analysisData: any) => {
    return await request.post({ url: `/erp/supplier-evaluation/ai-analysis`, data: analysisData })
  }
}
