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

// 获取我邀请的用户
export const invitedList = async () => {
  try {
    const response = await get(`/team/bd/invite-message-own`)
    return response
  } catch (error) {
    console.error('Failed to fetch get my agency:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取邀请我的用户
export const beInvitedList = async () => {
  try {
    const response = await get(`/team/bd/invite-message`)
    return response
  } catch (error) {
    console.error('Failed to fetch get my message:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 邀请成为代理
export const inviteToBeAgency = async (data) => {
  try {
    const response = await post(`/team/bd/invite-agent`, data)
    return response
  } catch (error) {
    console.error('Failed to invite to be agency:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 处理邀请
export const handleInvite = async (data) => {
  try {
    const response = await post(`/team/bd/invite-message-process`, data)
    return response
  } catch (error) {
    console.error('Failed to handle invite:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

//取消邀请
export const cancelInvite = async (userId) => {
  try {
    const response = await post(`/team/bd/invite-agent-cancel/${userId}`)
    return response
  } catch (error) {
    console.error('Failed to cancel invite:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 查询BD/BDLearer 成员账单列表
export const getBdMemberBillList = async (type) => {
  try {
    const response = await get(`/team/bd/member-bill/list?type=${type}`)
    return response
  } catch (error) {
    console.error('Failed to fetch BD member bill list:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 查询BD历史记录
export const getBdHistory = async () => {
  try {
    const response = await get(`/team/bd/history`)
    return response
  } catch (error) {
    console.error('Failed to fetch BD history:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 查询BD历史记录详情（More页面）
export const getBdHistoryMore = async (billBelong) => {
  try {
    const response = await get(`/team/bd/history/more?billBelong=${billBelong}`)
    return response
  } catch (error) {
    console.error('Failed to fetch BD history more:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 是否有赠送礼物的权限
export const hasSendGiftsPermission = async () => {
  try {
    const response = await get(`/sys/bd/own-permission`)
    return response
  } catch (error) {
    console.error('Failed to fetch has send gifts permission:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 获取赠送礼物的类型列表
export const getSendGiftsPermissionList = async () => {
  try {
    const response = await get(`/sys/bd/list-permission`)
    return response
  } catch (error) {
    console.error('Failed to fetch send gifts permission list:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// BD 可赠送礼物详情
export const getBDPropsList = async (params) => {
  try {
    const response = await get(
      `/sys/bd/props?propsType=${params.propsType}&currencyType=${params.currencyType}`,
    )
    return response
  } catch (error) {
    console.error('Failed to fetch admin center list:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// BD 赠送礼物
export const giveProps = async (data) => {
  try {
    const response = await post('/sys/bd/send', data)
    return response
  } catch (error) {
    console.error('Failed to fetch give props:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}
