import { z } from 'zod'
import 'dotenv/config'

const envSchema = z.object({
  PORT: z.string().default('8008'),
  NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
  JWT_SECRET: z.string().min(16),
  DATABASE_URL: z.string().url(),
  DRAGONFLY_URL: z.string().default('redis://localhost:6379'),
  DRAGONFLY_TTL_SECONDS: z.string().default('86400'),
  NATS_URL: z.string().default('nats://localhost:4222'),
  TEMPORAL_ADDRESS: z.string().default('localhost:7233'),
  TEMPORAL_NAMESPACE: z.string().default('default'),
  TEMPORAL_TASK_QUEUE: z.string().default('newwhats-queue'),
  BAILEYS_SESSIONS_PATH: z.string().default('./sessions'),
  FRONTEND_URL: z.string().default('http://localhost:3000'),
})

const parsed = envSchema.safeParse(process.env)

if (!parsed.success) {
  console.error('❌ Variáveis de ambiente inválidas:')
  console.error(parsed.error.format())
  process.exit(1)
}

export const env = parsed.data
