import { get, post } from '../utils/http.js'

// 获取礼物榜单
export const getWeekStarRanking = async (data) => {
  try {
    const response = await get(
      `/activity/week-star/ranking?type=${data.type}&current=${data.current}&size=${data.size}`,
    )
    return response
  } catch (error) {
    console.error('Failed to get week star ranking:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取我的排名
export const getMyWeekStarRanking = async (data) => {
  try {
    const response = await get(
      `/activity/week-star/my-rank?type=${data.type}&userId=${data.userId}`,
    )
    return response
  } catch (error) {
    console.error('Failed to get my week star ranking:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取本周奖励
export const getWeekRewards = async () => {
  try {
    const response = await get(`/activity/week-star/reward`)
    return response
  } catch (error) {
    console.error('Failed to get this week rewards:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取本周礼物
export const getWeekGifts = async (type) => {
  try {
    const response = await get(`/activity/week-star/gifts?type=${type}`)
    return response
  } catch (error) {
    console.error('Failed to get this week gifts:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取历史周星top1
export const getHistoryTopOne = async () => {
  try {
    const response = await get(`/activity/week-star/history-top1`)
    return response
  } catch (error) {
    console.error('Failed to get history top one:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取本周可兑换商品
export const getExchangeGoods = async (data) => {
  try {
    const response = await get(
      `/activity/week-star/listActivityResource?sysOrigin=${data.sysOrigin}&activityType=${data.activityType}`,
    )
    return response
  } catch (error) {
    console.error('Failed to get exchange goods:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取我拥有的碎片
export const getMyFragment = async (data) => {
  try {
    const response = await post(
      `/activity/week-star/list/by/user-id?userId=${data.userId}&fragmentsIds=${data.fragmentsIds}`,
    )
    return response
  } catch (error) {
    console.error('Failed to get my fragment:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 兑换商品
export const exchangeGood = async (data) => {
  try {
    const response = await post(`/activity/week-star/exchange`, data)
    return response
  } catch (error) {
    console.error('Failed to exchange goods:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}
