import { z } from 'zod';

const Env = z.object({
  DATABASE_URL: z.string(),
  REDIS_URL: z.string().default('redis://localhost:6379'),
  ANTHROPIC_API_KEY: z.string().optional(),
  GLM_API_KEY: z.string().optional(),
  RUNNER_HOST: z.string().default('localhost'),
  RUNNER_PORT_RANGE_START: z.coerce.number().default(4100),
  RUNNER_PORT_RANGE_END: z.coerce.number().default(4999),
  CONTROL_PLANE_URL: z.string().default('http://host.docker.internal:4000'),
  CONTROL_PLANE_PUBLIC_URL: z.string().default('http://localhost:4000'),
  OAUTH_ISSUER: z.string().optional(),
  MODEL_GENERATE: z.string().default('glm-4.5'),
  MODEL_FIX: z.string().default('claude-haiku-4-5-20251001'),
  // When set (e.g. "mcp.buildmymcpserver.com"), each deployed runner gets a
  // public URL of the form https://<slug>.<MCP_DOMAIN> instead of the legacy
  // http://<RUNNER_HOST>:<port> form. Requires host-side nginx + DNS setup
  // (see scripts/setup-runner-tls.sh). When unset, falls back to plain HTTP.
  MCP_DOMAIN: z.string().optional(),
  // Directory the generator drops per-runner map fragments into. A host-side
  // inotify service combines them and reloads nginx. Mounted as a volume by
  // docker-compose (see setup-runner-tls.sh).
  RUNNER_MAP_DIR: z.string().default('/var/runner-map'),
});

export const config = Env.parse(process.env);
