import { config } from 'dotenv'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { z } from 'zod'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

config({ path: path.join(__dirname, '..', '.env') })

const envSchema = z.object({
  PORT: z.coerce.number().default(3001),
  DATABASE_URL: z.string().min(1).default('postgresql://planner:planner1234@localhost:5432/ten_minute_planner'),
  CORS_ORIGIN: z.string().default('http://localhost:5173'),
  SESSION_TTL_DAYS: z.coerce.number().default(30),
  APP_BASE_URL: z.string().default('http://localhost:5173'),
  RESEND_API_KEY: z.string().optional(),
  MAIL_FROM_EMAIL: z.string().email().default('planner@sori.studio'),
  MAIL_FROM_NAME: z.string().default('10 Minute Planner'),
  AUTH_PREVIEW_LINKS: z.coerce.boolean().default(false),
  ADMIN_ACCOUNT_ID: z.string().min(1),
  ADMIN_ACCOUNT_PASSWORD: z.string().min(12),
  ADMIN_ACCOUNT_EMAIL: z.string().email(),
  ADMIN_ACCOUNT_NICKNAME: z.string().min(1),
})

export const env = envSchema.parse(process.env)
