import request from '@/utils/request'
import type {
  ShopSeckill,
  ShopSeckillOrder,
  ShopSeckillPageParams,
} from './model'

/** 获取秒杀商品列表 */
export function pageShopSeckill(params: ShopSeckillPageParams = {}) {
  return request.post<{ items: ShopSeckill[]; total: number }>('/shopSeckill/page', params)
}

/** 获取秒杀商品详情 */
export function getShopSeckill(id: number) {
  return request.post<ShopSeckill>('/shopSeckill/get', { id })
}

/** 创建秒杀订单 */
export function createSeckillOrder(data: { seckillId: number; goodsId: number; skuId: number; quantity: number }) {
  return request.post<ShopSeckillOrder>('/shopSeckill/createOrder', data)
}

/** 获取我的秒杀订单 */
export function mySeckillOrders(params: { page?: number; pageSize?: number } = {}) {
  return request.post<{ items: ShopSeckillOrder[]; total: number }>('/shopSeckill/myOrders', params)
}

/** 获取秒杀时间段（场次） */
export function getSeckillTimeSlots() {
  return request.post<Array<{ startTime: string; endTime: string; status: number }>>('/shopSeckill/timeSlots', {})
}
