function parseEnable(v: unknown): boolean {
  if (typeof v === 'string') {
    const s = v.trim().toLowerCase()
    return s === 'true' || s === '1' || s === 'yes' || s === 'on'
  }
  if (typeof v === 'boolean') return v
  if (typeof v === 'number') return v === 1
  return true
}

export const Env = {
  API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '',
  MIDTRANS_CLIENT_KEY: import.meta.env.VITE_MIDTRANS_CLIENT_KEY || '',
  MIDTRANS_ENV: (import.meta.env.VITE_MIDTRANS_ENV as 'sandbox' | 'production') || 'sandbox',
  LOG_LEVEL: ((import.meta.env.VITE_LOG_LEVEL as string) || 'info').toLowerCase() as 'debug' | 'info' | 'warn' | 'error',
  // Feature toggles per payment type (frontend)
  ENABLE_BANK_TRANSFER: parseEnable(import.meta.env.VITE_ENABLE_BANK_TRANSFER),
  ENABLE_CREDIT_CARD: parseEnable(import.meta.env.VITE_ENABLE_CREDIT_CARD),
  ENABLE_GOPAY: parseEnable(import.meta.env.VITE_ENABLE_GOPAY),
  ENABLE_CSTORE: parseEnable(import.meta.env.VITE_ENABLE_CSTORE),
  ENABLE_CPAY: parseEnable(import.meta.env.VITE_ENABLE_CPAY),
}