import { getAuthRuntimeConfig, validateAuthRuntimeConfig } from './auth-env'

const authRuntime = getAuthRuntimeConfig()
const authRuntimeValidation = validateAuthRuntimeConfig()

const env = import.meta.env as Record<string, string | undefined>

export const SUPERTOKENS_API_DOMAIN = authRuntime.superTokensApiDomain
export const SUPERTOKENS_WEBSITE_DOMAIN = authRuntime.superTokensWebsiteDomain
export const SUPERTOKENS_API_BASE_PATH = authRuntime.superTokensApiBasePath
export const SUPERTOKENS_WEBSITE_BASE_PATH = authRuntime.superTokensWebsiteBasePath

const GITHUB_OAUTH_ENABLED = String(env.VITE_GITHUB_OAUTH_ENABLED || '').toLowerCase() === 'true'
const GOOGLE_OAUTH_ENABLED = String(env.VITE_GOOGLE_OAUTH_ENABLED || '').toLowerCase() === 'true'
const ORCID_OAUTH_ENABLED = String(env.VITE_ORCID_OAUTH_ENABLED || '').toLowerCase() === 'true'

export function isSuperTokensConfigured() {
  return Boolean(SUPERTOKENS_API_DOMAIN)
}

export function isGitHubOAuthEnabled() {
  return GITHUB_OAUTH_ENABLED
}

export function isGoogleOAuthEnabled() {
  return GOOGLE_OAUTH_ENABLED
}

export function isOrcidOAuthEnabled() {
  return ORCID_OAUTH_ENABLED
}

export function getSuperTokensAuthRuntimeValidation() {
  return authRuntimeValidation
}
