import { z } from "zod";
import {
  validateMintelEnv,
  mintelEnvSchema,
  withMintelRefinements,
} from "@mintel/next-utils";

const envExtension = {
  AUTH_COOKIE_NAME: z.string().default("mintel_gatekeeper_session"),

  // Analytics
  UMAMI_WEBSITE_ID: z.string().optional(),
  NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string().optional(),
  UMAMI_API_ENDPOINT: z.string().url().optional(),

  // Features
  SHOW_BLOG: z
    .string()
    .transform((v) => v === "true")
    .default("false"),
};

/**
 * Environment variable schema for the main website.
 * Extends the default Mintel environment schema.
 */
export const envSchema = withMintelRefinements(
  z.object(mintelEnvSchema).extend(envExtension),
);

/**
 * Validated environment object.
 */
export const env = validateMintelEnv(envExtension);

/**
 * For legacy compatibility with existing code.
 */
export function getRawEnv() {
  return env;
}
