/**
 * Environment variable validation and access
 */

const requiredEnvVars = {
  // Add required env vars here as they are needed
  // NEXT_PUBLIC_GRAPHQL_ENDPOINT: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT,
} as const

const optionalEnvVars = {
  NEXT_PUBLIC_GRAPHQL_ENDPOINT: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || '/api/graphql',
  NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000',
  NODE_ENV: process.env.NODE_ENV || 'development',
  NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
  NEXT_PUBLIC_ANALYTICS_ID: process.env.NEXT_PUBLIC_ANALYTICS_ID,
} as const

/**
 * Validate required environment variables
 */
export function validateEnv() {
  const missing: string[] = []

  for (const [key, value] of Object.entries(requiredEnvVars)) {
    if (!value) {
      missing.push(key)
    }
  }

  if (missing.length > 0) {
    throw new Error(
      `Missing required environment variables: ${missing.join(', ')}\n` +
        'Please check your .env file or environment configuration.'
    )
  }
}

/**
 * Get environment variable value
 */
export function getEnv(key: keyof typeof optionalEnvVars): string | undefined {
  return optionalEnvVars[key]
}

/**
 * Get all environment variables (for debugging)
 */
export function getAllEnv() {
  return {
    ...requiredEnvVars,
    ...optionalEnvVars,
  }
}

// Validate on module load in production
if (typeof window === 'undefined' && process.env.NODE_ENV === 'production') {
  validateEnv()
}

