import { z } from "zod";

const envSchema = z.object({
    DISCORD_BOT_TOKEN: z.string().optional(),
    DISCORD_CLIENT_ID: z.string().optional(),
    DISCORD_GUILD_ID: z.string().optional(),
    DATABASE_URL: z.string().min(1, "Database URL is required"),
    PORT: z.coerce.number().default(3000),
});

const parsedEnv = envSchema.safeParse(process.env);

if (!parsedEnv.success) {
    console.error("❌ Invalid environment variables:", parsedEnv.error.flatten().fieldErrors);
    throw new Error("Invalid environment variables");
}

export const env = parsedEnv.data;
