import request from '@/utils/request'

/**
 * 生成二维码邀请
 */
export function generateInviteQrCode(data: {
  appId: number
  role: string
}) {
  return request.post<{
    code: number
    message: string
    data: {
      qrCodeUrl: string
      inviteUrl: string  // 邀请链接，用于前端生成二维码
      token: string
      expireTime: string
    }
  }>('/api/app/developer/invite/qrcode', data)
}

/**
 * 生成链接邀请
 */
export function generateInviteLink(data: {
  appId: number
  role: string
}) {
  return request.post<{
    code: number
    message: string
    data: {
      inviteUrl: string
      token: string
      expireTime: string
    }
  }>('/api/app/developer/invite/link', data)
}

/**
 * 验证邀请
 */
export function verifyInvite(data: {
  token: string
  appId?: number
}) {
  return request.post<{
    code: number
    message: string
    data: {
      valid: boolean
      appId: number
      appName: string
      role: string
      inviterName: string
      inviterAvatar?: string
      expireTime: string
    }
  }>('/api/app/developer/invite/verify', data)
}

/**
 * 接受邀请
 */
export function acceptInvite(data: {
  token: string
  appId?: number
  role?: string
}) {
  return request.post<{
    code: number
    message: string
    data: null
  }>('/api/app/developer/invite/accept', data)
}
