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

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

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

/**
 * 抢购下单（需登录）
 * POST /api/seckill/buy
 */
export function seckillBuyApi(data: SeckillBuyReq) {
  return request<{ orderNo: string }>({
    url: '/api/seckill/buy',
    method: 'POST',
    data
  })
}

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