import { z } from 'zod';
const envSchema = z.object({
    LICENSE_DB_PATH: z.string().default(''),
    CHECKOUT_API_URL: z.string().url({
        message: 'CHECKOUT_API_URL must be a valid URL (e.g. https://api.ocrprovenance.com)',
    }),
    SESSION_SECRET: z.string().min(32),
    LICENSE_SIGNING_KEY: z.string().length(64),
    LICENSE_PUBLIC_KEY: z.string().length(64),
    DASHBOARD_URL: z.string().url(),
    WORKER_AUTH_SECRET: z.string().min(32, {
        message: 'WORKER_AUTH_SECRET must be at least 32 characters',
    }),
    WEBHOOK_SHARED_SECRET: z.string().min(32, {
        message: 'WEBHOOK_SHARED_SECRET must be at least 32 characters',
    }),
    RESEND_API_KEY: z.string().startsWith('re_').optional(),
    FROM_EMAIL: z.string().email().default('noreply@ocrprovenance.com'),
    LICENSE_PORT: z.coerce.number().default(3000),
    ADMIN_EMAILS: z.string().default(''),
});
let _env = null;
export function loadEnv() {
    if (_env)
        return _env;
    const result = envSchema.safeParse(process.env);
    if (!result.success) {
        const errors = result.error.issues.map(i => `  ${i.path.join('.')}: ${i.message}`).join('\n');
        console.error(`[FATAL] Invalid environment variables:\n${errors}`);
        process.exit(1);
    }
    _env = result.data;
    return _env;
}
export function getEnv() {
    if (!_env)
        throw new Error('Environment not loaded. Call loadEnv() first.');
    return _env;
}
//# sourceMappingURL=env.js.map