import { request, type ApiResponse } from '@/utils/request'

// ==================== 指定中奖配置相关类型定义 ====================

/** 指定中奖配置项 */
export interface DesignatedPrizeItem {
  id: number
  goodsId: number
  goodsItemId: number
  goodsItemTitle: string | null
  goodsItemImgUrl: string | null
  userId: number
  userNickname: string | null
  userPhone: string | null
  isActive: boolean
  remark: string | null
  createdAt: string
}

/** 创建指定中奖配置请求 */
export interface CreateDesignatedPrizeRequest {
  goodsItemId: number
  userId: number
  remark?: string
}

/** 更新指定中奖配置请求 */
export interface UpdateDesignatedPrizeRequest {
  userId?: number
  isActive?: boolean
  remark?: string
}

// ==================== 指定中奖配置 API ====================

/** 获取商品的指定中奖配置列表 */
export function getDesignatedPrizes(goodsId: number): Promise<ApiResponse<DesignatedPrizeItem[]>> {
  return request({
    url: `/admin/goods/${goodsId}/designated-prizes`,
    method: 'get'
  })
}

/** 创建指定中奖配置 */
export function createDesignatedPrize(
  goodsId: number, 
  data: CreateDesignatedPrizeRequest
): Promise<ApiResponse<DesignatedPrizeItem>> {
  return request({
    url: `/admin/goods/${goodsId}/designated-prizes`,
    method: 'post',
    data
  })
}

/** 更新指定中奖配置 */
export function updateDesignatedPrize(
  goodsId: number, 
  id: number, 
  data: UpdateDesignatedPrizeRequest
): Promise<ApiResponse<DesignatedPrizeItem>> {
  return request({
    url: `/admin/goods/${goodsId}/designated-prizes/${id}`,
    method: 'put',
    data
  })
}

/** 删除指定中奖配置 */
export function deleteDesignatedPrize(goodsId: number, id: number): Promise<ApiResponse<string>> {
  return request({
    url: `/admin/goods/${goodsId}/designated-prizes/${id}`,
    method: 'delete'
  })
}
