import { config } from "dotenv"
import { z } from "zod"

config()

const envSchema = z.object({
  DATABASE_PATH: z.string().default("./mikrotik.db"),
  PORT: z.coerce.number().int().positive().default(8000),
  CORS_ORIGIN: z.string().default("http://localhost:3000"),
})

const parsed = envSchema.safeParse(process.env)

if (!parsed.success) {
  console.error("❌ Invalid environment variables:", parsed.error.flatten().fieldErrors)
  process.exit(1)
}

export const env = parsed.data
