import request from '@/config/axios'

export interface AnalysisQueryParams {
  registerCreateTime?: string[]
  processFinishTime?: string[]
  visitCreateTime?: string[]
  pageSize?: number
}

export interface DistItem {
  name: string
  value: number
}

export interface RegisterSummary {
  total: number
  pending: number
  approved: number
  rejected: number
}

export interface ProcessSummary {
  total: number
  processing: number
  completed: number
  failed: number
}

export interface VisitSummary {
  total: number
  avgRating: number
  fiveStar: number
  highRepurchase: number
}

export interface RegisterAnalysisResponse {
  registerSummary?: RegisterSummary
  registerTypeDist?: DistItem[]
  registerStatusDist?: DistItem[]
}

export interface ProcessAnalysisResponse {
  processSummary?: ProcessSummary
  processTypeDist?: DistItem[]
  processStatusDist?: DistItem[]
}

export interface VisitAnalysisResponse {
  visitSummary?: VisitSummary
  visitRatingDist?: DistItem[]
  visitRepurchaseDist?: DistItem[]
}

export const AfterSaleAnalysisApi = {
  getAnalysis: async (params: AnalysisQueryParams) => {
    return await request.post({ url: '/erp/after-sale/analysis', data: params })
  }
}
