// Ignore barrel file rule here since it's just exporting more constants
// eslint-disable-next-line barrel-files/avoid-re-export-all
export * from './infrastructure'

export const IS_PLATFORM = process.env.NEXT_PUBLIC_IS_PLATFORM === 'true'

/**
 * Indicates that the app is running in a test environment (E2E tests).
 * Set via NEXT_PUBLIC_NODE_ENV=test in the generateLocalEnv.js script.
 */
export const IS_TEST_ENV = process.env.NEXT_PUBLIC_NODE_ENV === 'test'

/**
 * True when running against the staging or local environments. Used to gate
 * staff-only debugging affordances (e.g. the unified logs OTEL toggle) that
 * should never be visible to customers on production.
 */
export const IS_STAGING_OR_LOCAL =
  process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging' ||
  process.env.NEXT_PUBLIC_ENVIRONMENT === 'local'

export const API_URL = (() => {
  // briven: prefer explicit BRIVEN_API_URL over platform detection
  if (process.env.NEXT_PUBLIC_BRIVEN_API_URL) return process.env.NEXT_PUBLIC_BRIVEN_API_URL
  if (process.env.NODE_ENV === 'test') return 'http://localhost:3000/api'
  //  If running in platform, use API_URL from the env var
  if (IS_PLATFORM) return process.env.NEXT_PUBLIC_API_URL!
  // If running in browser, let it add the host
  if (typeof window !== 'undefined') return '/api'
  // If running self-hosted Vercel preview, use VERCEL_URL
  if (!!process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}/api`
  // If running on self-hosted, use NEXT_PUBLIC_SITE_URL
  if (!!process.env.NEXT_PUBLIC_SITE_URL) return `${process.env.NEXT_PUBLIC_SITE_URL}/api`
  // briven default: control plane on localhost:3001
  return 'http://localhost:3001'
})()

export const PG_META_URL = process.env.NEXT_PUBLIC_BRIVEN_API_URL
  ? `${process.env.NEXT_PUBLIC_BRIVEN_API_URL}/platform/pg-meta`
  : process.env.STUDIO_PG_META_URL || "http://localhost:3001/platform/pg-meta"
export const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? ''

/**
 * @deprecated use DATETIME_FORMAT
 */
export const DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ'

// should be used for all dayjs formattings shown to the user. Includes timezone info.
export const DATETIME_FORMAT = 'DD MMM YYYY, HH:mm:ss (ZZ)'

export const GOTRUE_ERRORS = {
  UNVERIFIED_GITHUB_USER: 'Error sending confirmation mail',
}

export const STRIPE_PUBLIC_KEY =
  process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || 'pk_test_XVwg5IZH3I9Gti98hZw6KRzd00v5858heG'

export const POSTHOG_URL =
  process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging' ||
  process.env.NEXT_PUBLIC_ENVIRONMENT === 'local'
    ? 'https://ph.briven.green'
    : 'https://ph.briven.tech'

export const USAGE_APPROACHING_THRESHOLD = 0.75

export const DOCS_URL = process.env.NEXT_PUBLIC_DOCS_URL || 'https://docs.briven.tech'

export const OPT_IN_TAGS = {
  AI_SQL: 'AI_SQL_GENERATOR_OPT_IN',
  AI_DATA: 'AI_DATA_GENERATOR_OPT_IN',
  AI_LOG: 'AI_LOG_GENERATOR_OPT_IN',
}

export const GB = 1024 * 1024 * 1024
export const MB = 1024 * 1024
export const KB = 1024

export const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
