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

// 获取任务列表
export const apiTaskList = async (data) => {
  try {
    const response = await post(`/admin/task/query`, data)
    return response
  } catch (error) {
    console.error('Failed to fetch task list:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

//查询团队概览
export const apiGetTeamOverview = async (data) => {
  try {
    const response = await post('/bd/team/overview', data)
    return response
  } catch (error) {
    console.error('Failed to get team overview:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 查询团队成员详情（More弹框）
export const apiGetTeamMemberDetail = async (data) => {
  try {
    const response = await post('/bd/team/member/detail', data)
    return response
  } catch (error) {
    console.error('Failed to get team member detail:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 查询团队总览
export const apiGetTeamSummary = async (data) => {
  try {
    const response = await post('/bd/team/summary', data)
    return response
  } catch (error) {
    console.error('Failed to get team summary:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

// 检查权限
export const apiGetTeamPermissionCheck = async (data) => {
  try {
    const response = await post('/bd/team/permission/check', data)
    return response
  } catch (error) {
    console.error('Failed to check team permission:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

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

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

// 获取邀请我成为bdleader的用户
export const myBeInvitedList_BDLeader = async () => {
  try {
    const response = await get(`/team/bd/invite-bdleader-message`)
    return response
  } catch (error) {
    console.error('Failed to fetch users who invited me to be BDLeader:', error)
    console.error('error:' + error.response.errorMsg)
    throw error
  }
}

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

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

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

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

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

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

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