import { z } from "zod";

const envSchema = z.object({
	NODE_ENV: z.enum(["development", "production", "test"]).default("production"),
	PORT: z.coerce.number().int().positive().default(3001),
	REDIS_URL: z.string().url().default("redis://redis:6379"),
	RESULTS_DIR: z.string().min(1).default("/data/results"),
	HEADLESS: z
		.union([z.literal("true"), z.literal("false")])
		.default("true")
		.transform((v) => v === "true"),
	MAX_CONCURRENT: z.coerce.number().int().positive().default(1),
	EXTRA_SITESPEED_ARGS: z.string().default(""),
	// Absolute path to the sitespeed CLI inside the image. The official
	// docker image installs it under /usr/src/app/bin/sitespeed.js.
	SITESPEED_BIN: z.string().default("/usr/src/app/bin/sitespeed.js"),
	// Lighthouse plugin path — globally installed in the plus1 image.
	LIGHTHOUSE_PLUGIN_PATH: z
		.string()
		.default("/usr/local/lib/node_modules/@sitespeed.io/plugin-lighthouse"),
});

export type Env = z.infer<typeof envSchema>;

export const env: Env = envSchema.parse(process.env);
