import { request } from '@/utils/request'
import type { SeckillActivity, SeckillResult } from '@/types'

/** 抢购活动列表（进行中/即将开始） */
export function getSeckillActivitiesApi() {
  return request<SeckillActivity[]>({
    url: '/api/seckill/activities',
    method: 'GET'
  })
}

/** 抢购活动详情 */
export function getSeckillActivityApi(id: number) {
  return request<SeckillActivity>({
    url: `/api/seckill/activities/${id}`,
    method: 'GET'
  })
}

/**
 * 抢购下单
 * 后端：POST /api/seckill/buy
 * 响应：{ orderNo }（排队号/订单号）
 */
export function seckillBuyApi(data: { activityId: number; skuId: number; quantity?: number }) {
  return request<{ orderNo: string }>({
    url: '/api/seckill/buy',
    method: 'POST',
    data
  })
}

/** 轮询查询抢购结果 */
export function getSeckillResultApi(orderNo: string) {
  return request<SeckillResult>({
    url: `/api/seckill/result/${orderNo}`,
    method: 'GET'
  })
}
