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),
    HOST: z.string().default("127.0.0.1"),
    ADMIN_TOKEN: z.string().min(8, "ADMIN_TOKEN must be at least 8 characters").optional(),
});

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;
