import { request } from '@/utils/request'

/**
 * 仪表盘统计 API
 *
 * 后端契约：com.snack.server.module.dashboard.controller.DashboardController
 *   GET /api/admin/dashboard/stats         → DashboardStats
 *   GET /api/admin/dashboard/sales-trend   → {date, amount}[]（?days=7|30）
 *   GET /api/admin/dashboard/order-status  → {name, value}[]
 *   GET /api/admin/dashboard/hot-products  → {name, sales}[]
 */

export interface DashboardStats {
  todayOrders: number
  todaySales: number
  totalUsers: number
  totalProducts: number
}

export interface TrendPoint {
  date: string
  amount: number
}

export interface NameValueVO {
  name: string
  value: number
}

export interface HotProductVO {
  name: string
  sales: number
}

export function getDashboardStatsApi() {
  return request<DashboardStats>({
    url: '/api/admin/dashboard/stats',
    method: 'GET'
  })
}

export function getSalesTrendApi(days: number) {
  return request<TrendPoint[]>({
    url: '/api/admin/dashboard/sales-trend',
    method: 'GET',
    params: { days }
  })
}

export function getOrderStatusDistributionApi() {
  return request<NameValueVO[]>({
    url: '/api/admin/dashboard/order-status',
    method: 'GET'
  })
}

export function getHotProductsApi() {
  return request<HotProductVO[]>({
    url: '/api/admin/dashboard/hot-products',
    method: 'GET'
  })
}
