// Discord OAuth配置
const DISCORD_CLIENT_ID = process.env.NEXT_PUBLIC_DISCORD_CLIENT_ID!
const DISCORD_REDIRECT_URI = `${process.env.NEXT_PUBLIC_APP_URL || 'https://test.crushlevel.ai'}/api/auth/discord/callback`

// Discord OAuth scopes
const DISCORD_SCOPES = ['identify', 'email']

export interface DiscordUser {
  id: string
  username: string
  email: string
  avatar?: string
  discriminator: string
}

export interface DiscordTokenResponse {
  access_token: string
  token_type: string
  expires_in: number
  refresh_token: string
  scope: string
}

export const discordOAuth = {
  // 获取Discord授权URL
  getAuthUrl: (state?: string): string => {
    const params = new URLSearchParams({
      client_id: DISCORD_CLIENT_ID,
      redirect_uri: DISCORD_REDIRECT_URI,
      response_type: 'code',
      scope: DISCORD_SCOPES.join(' '),
      ...(state && { state })
    })
    
    return `https://discord.com/api/oauth2/authorize?${params.toString()}`
  }

  // 注意：token交换和用户信息获取将在后端处理
  // 前端只负责获取授权码并传递给后端API
} 