/**
 * OAuth Provider Credentials
 * Maps provider IDs to environment variable names
 * Single source of truth for credential lookup
 */

const PROVIDER_ENV_VARS: Record<string, { clientIdEnv: string; clientSecretEnv: string }> = {
  'google-sheets': {
    clientIdEnv: 'GOOGLE_OAUTH_CLIENT_ID',
    clientSecretEnv: 'GOOGLE_OAUTH_CLIENT_SECRET'
  },
  'google-calendar': {
    clientIdEnv: 'GOOGLE_OAUTH_CLIENT_ID',
    clientSecretEnv: 'GOOGLE_OAUTH_CLIENT_SECRET'
  },
  dropbox: {
    clientIdEnv: 'DROPBOX_APP_KEY',
    clientSecretEnv: 'DROPBOX_APP_SECRET'
  }
}

/**
 * Get OAuth client credentials for a provider
 * @throws Error if provider unknown or credentials missing
 */
export function getOAuthCredentials(providerId: string): { clientId: string; clientSecret: string } {
  const config = PROVIDER_ENV_VARS[providerId]
  if (!config) {
    throw new Error(`Unknown OAuth provider: ${providerId}`)
  }

  const clientId = process.env[config.clientIdEnv]
  const clientSecret = process.env[config.clientSecretEnv]

  if (!clientId) {
    throw new Error(`Missing environment variable: ${config.clientIdEnv}`)
  }
  if (!clientSecret) {
    throw new Error(`Missing environment variable: ${config.clientSecretEnv}`)
  }

  return { clientId, clientSecret }
}
