import { createEnv } from "@t3-oss/env-nextjs"
import { z } from "zod"

export const env = createEnv({
  /**
   * Due to t3-env only checking typeof window === "undefined"
   * and Netlify running Deno, window is never "undefined"
   * https://github.com/t3-oss/t3-env/issues/154
   */
  isServer: typeof window === "undefined" || "Deno" in window,
  server: {
    ADOBE_SCRIPT_SRC: z.string().optional(),
    API_BASEURL: z.string(),
    BUILD_ID: z.string().default("64rYXBu8o2eHp0Jf"),
    CMS_ACCESS_TOKEN: z.string(),
    CMS_API_KEY: z.string(),
    CMS_ENVIRONMENT: z.enum(["development", "production", "stage", "test"]),
    CMS_PREVIEW_TOKEN: z.string(),
    CMS_PREVIEW_URL: z.string(),
    CMS_URL: z.string(),
    CURITY_CLIENT_ID_USER: z.string(),
    CURITY_CLIENT_SECRET_USER: z.string(),
    CURITY_ISSUER_USER: z.string(),
    CYPRESS_BASE_URL: z.string().default("http://127.0.0.1:3000"),
    DESIGN_SYSTEM_ACCESS_TOKEN: z.string(),
    ENVTEST: z.string().optional(),
    // https://env.t3.gg/docs/recipes#booleans
    NEXTAUTH_DEBUG: z
      .string()
      .refine((s) => s === "true" || s === "false")
      .transform((s) => s === "true")
      .default("false"),
    NEXTAUTH_REDIRECT_PROXY_URL: z.string().optional(),
    NEXTAUTH_SECRET: z.string(),
    NEXTAUTH_URL: z.string().optional(),
    AUTH_URL: z.string().optional(),
    NODE_ENV: z.enum(["development", "test", "production"]),
    PRINT_QUERY: z
      .string()
      .refine((s) => s === "true" || s === "false")
      .transform((s) => s === "true")
      .default("false"),
    PUBLIC_URL: z.string().optional(),
    REVALIDATE_SECRET: z.string(),
    SEAMLESS_LOGIN_DA: z.string(),
    SEAMLESS_LOGIN_DE: z.string(),
    SEAMLESS_LOGIN_EN: z.string(),
    SEAMLESS_LOGIN_FI: z.string(),
    SEAMLESS_LOGIN_NO: z.string(),
    SEAMLESS_LOGIN_SV: z.string(),
    SEAMLESS_LOGOUT_DA: z.string(),
    SEAMLESS_LOGOUT_DE: z.string(),
    SEAMLESS_LOGOUT_EN: z.string(),
    SEAMLESS_LOGOUT_FI: z.string(),
    SEAMLESS_LOGOUT_NO: z.string(),
    SEAMLESS_LOGOUT_SV: z.string(),
    WEBVIEW_ENCRYPTION_KEY: z.string(),
  },
  emptyStringAsUndefined: true,
  runtimeEnv: {
    ADOBE_SCRIPT_SRC: process.env.ADOBE_SCRIPT_SRC,
    API_BASEURL: process.env.API_BASEURL,
    BUILD_ID: process.env.BUILD_ID,
    CMS_ACCESS_TOKEN: process.env.CMS_ACCESS_TOKEN,
    CMS_API_KEY: process.env.CMS_API_KEY,
    CMS_ENVIRONMENT: process.env.CMS_ENVIRONMENT,
    CMS_PREVIEW_TOKEN: process.env.CMS_PREVIEW_TOKEN,
    CMS_PREVIEW_URL: process.env.CMS_PREVIEW_URL,
    CMS_URL: process.env.CMS_URL,
    CURITY_CLIENT_ID_USER: process.env.CURITY_CLIENT_ID_USER,
    CURITY_CLIENT_SECRET_USER: process.env.CURITY_CLIENT_SECRET_USER,
    CURITY_ISSUER_USER: process.env.CURITY_ISSUER_USER,
    CYPRESS_BASE_URL: process.env.CYPRESS_TEST_URL,
    DESIGN_SYSTEM_ACCESS_TOKEN: process.env.DESIGN_SYSTEM_ACCESS_TOKEN,
    ENVTEST: process.env.ENVTEST,
    NEXTAUTH_DEBUG: process.env.NEXTAUTH_DEBUG,
    NEXTAUTH_REDIRECT_PROXY_URL: process.env.NEXTAUTH_REDIRECT_PROXY_URL,
    NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
    NEXTAUTH_URL: process.env.NEXTAUTH_URL,
    AUTH_URL: process.env.AUTH_URL,
    NODE_ENV: process.env.NODE_ENV,
    PRINT_QUERY: process.env.PRINT_QUERY,
    PUBLIC_URL: process.env.PUBLIC_URL,
    REVALIDATE_SECRET: process.env.REVALIDATE_SECRET,
    SEAMLESS_LOGIN_DA: process.env.SEAMLESS_LOGIN_DA,
    SEAMLESS_LOGIN_DE: process.env.SEAMLESS_LOGIN_DE,
    SEAMLESS_LOGIN_EN: process.env.SEAMLESS_LOGIN_EN,
    SEAMLESS_LOGIN_FI: process.env.SEAMLESS_LOGIN_FI,
    SEAMLESS_LOGIN_NO: process.env.SEAMLESS_LOGIN_NO,
    SEAMLESS_LOGIN_SV: process.env.SEAMLESS_LOGIN_SV,
    SEAMLESS_LOGOUT_DA: process.env.SEAMLESS_LOGOUT_DA,
    SEAMLESS_LOGOUT_DE: process.env.SEAMLESS_LOGOUT_DE,
    SEAMLESS_LOGOUT_EN: process.env.SEAMLESS_LOGOUT_EN,
    SEAMLESS_LOGOUT_FI: process.env.SEAMLESS_LOGOUT_FI,
    SEAMLESS_LOGOUT_NO: process.env.SEAMLESS_LOGOUT_NO,
    SEAMLESS_LOGOUT_SV: process.env.SEAMLESS_LOGOUT_SV,
    WEBVIEW_ENCRYPTION_KEY: process.env.WEBVIEW_ENCRYPTION_KEY,
  },
})
