import service from '@/utils/request/index'
import type {
  BackendAuctionListSearchParams,
  BackendAuctionListItemDto,
  BackendDeleteAuctionDto,
  BackendAddOrUpdateAuctionItemDto,
  BackendAuctionRecordItemDto,
  BackendLotteryPrizeListSearchParams,
  BackendLotteryPrizeListItemDto,
  BackendAddOrUpdateLotteryPrizeDto,
  BackendAddOrUpdateLotteryConfigDto,
  BackendLotteryConfigDto,
  BackendWheelPrizeListSearchParams,
  BackendWheelPrizeListItemDto,
  BackendAddOrUpdateWheelPrizeDto,
  BackendAddOrUpdateWheelConfigDto,
  BackendWheelConfigDto,
} from './types'
import type { BackendServicePageResult } from '@/utils/request/types'
import { BooleanFlag } from '@/constants'
// 后台管理限时竞拍相关接口

/**
 * 限时竞拍后台列表
 */
export const getBackendAuctionList = (data: BackendAuctionListSearchParams) => {
  return service.request<BackendServicePageResult<BackendAuctionListItemDto>>({
    url: 'api/cultureAuctionItems/listByPage',
    method: 'POST',
    data,
  })
}

/**
 * 新增或者编辑竞拍物品
 */
export const addOrUpdateAuctionItem = (data: BackendAddOrUpdateAuctionItemDto) => {
  return service.request({
    url: 'api/cultureAuctionItems/addOrUpdateAuctionItem',
    method: 'POST',
    data,
  })
}

/**
 * 删除竞拍物品数据
 */
export const deleteAuction = (data: BackendDeleteAuctionDto) => {
  return service.request({
    url: 'api/cultureAuctionItems/deleteAuction',
    method: 'POST',
    data,
  })
}

/**
 * 批量修改展示竞拍
 */
export const batchUpdateShowAuction = (data: { idList: number[]; isDisplay: BooleanFlag }) => {
  return service.request({
    url: 'api/cultureAuctionItems/changeAuctionDisplay',
    method: 'POST',
    data,
  })
}

/**
 * 获取竞拍记录
 */
export const getAuctionRecord = (data: BackendAuctionRecordItemDto) => {
  return service.request<BackendServicePageResult<BackendAuctionRecordItemDto>>({
    url: `api/cultureAuctionItems/listBidRecord`,
    method: 'POST',
    data,
  })
}

// 限时抽奖相关的后台接口
/**
 * 获取限时抽奖物品列表
 */
export const getLotteryPrizeList = (data: BackendLotteryPrizeListSearchParams) => {
  return service.request<BackendServicePageResult<BackendLotteryPrizeListItemDto>>({
    url: `/api/cultureLotteryPrizes/listPrizesByPage`,
    method: 'POST',
    data,
  })
}

// 新增或修改奖品池数据
export const addOrUpdateLotteryPrize = (data: BackendAddOrUpdateLotteryPrizeDto) => {
  return service.request({
    url: `/api/cultureLotteryPrizes/addOrUpdateLotteryPrizes`,
    method: 'POST',
    data,
  })
}

/**
 * 删除奖品池数据
 */
export const deleteLotteryPrize = (idList: number[]) => {
  return service.request({
    url: `/api/cultureLotteryPrizes/deleteLotteryPrizes`,
    method: 'POST',
    data: { idList },
  })
}

/**
 * 获取抽奖配置详情
 */
export const getLotteryConfigDetail = () => {
  return service.request<BackendLotteryConfigDto>({
    url: `/api/cultureLotteryPrizes/getConfigBackgroundDetail`,
    method: 'POST',
  })
}

/**
 * 修改抽奖配置
 */
export const setLotteryConfig = (data: BackendAddOrUpdateLotteryConfigDto) => {
  return service.request({
    url: `/api/cultureLotteryPrizes/dealConfig`,
    method: 'POST',
    data,
  })
}

// ========== 大转盘抽奖 ==========

export const getWheelPrizeList = (data: BackendWheelPrizeListSearchParams) => {
  return service.request<BackendServicePageResult<BackendWheelPrizeListItemDto>>({
    url: '/api/cultureWheelPrizes/listPrizesByPage',
    method: 'POST',
    data,
  })
}

export const addOrUpdateWheelPrize = (data: BackendAddOrUpdateWheelPrizeDto) => {
  return service.request({
    url: '/api/cultureWheelPrizes/addOrUpdatePrize',
    method: 'POST',
    data,
  })
}

export const deleteWheelPrize = (idList: number[]) => {
  return service.request({
    url: '/api/cultureWheelPrizes/deletePrizes',
    method: 'POST',
    data: { idList },
  })
}

export const getWheelConfig = () => {
  return service.request<BackendWheelConfigDto>({
    url: '/api/cultureWheelPrizes/getWheelConfig',
    method: 'POST',
  })
}

export const setWheelConfig = (data: BackendAddOrUpdateWheelConfigDto) => {
  return service.request({
    url: '/api/cultureWheelPrizes/setWheelConfig',
    method: 'POST',
    data,
  })
}
