/**
 * Cowork Service configuration — Zod-validated environment variables.
 *
 * Extends @bytelyst/backend-config baseBackendConfigSchema (same pattern as
 * FlowMonk, ActionTrail, NoteLett, and all other product backends).
 *
 * Port: 4009 (default)
 * Product: clawcowork
 */

import { z } from 'zod';
import { baseBackendConfigSchema } from '@bytelyst/backend-config';
import { productConfig } from './product-config.js';

const envSchema = baseBackendConfigSchema.extend({
  PORT: baseBackendConfigSchema.shape.PORT.default(productConfig.backendPort),
  SERVICE_NAME: baseBackendConfigSchema.shape.SERVICE_NAME.default('cowork-service'),
  // cowork-service is a bridge — no Cosmos containers of its own
  DB_PROVIDER: baseBackendConfigSchema.shape.DB_PROVIDER.default('memory'),
  JWT_SECRET: z.string().default('dev-secret-do-not-use-in-prod'),

  // Platform-service connection (for auth, flags, audit, etc.)
  PLATFORM_SERVICE_URL: z.string().default('http://localhost:4003'),

  // Extraction-service connection (for AI-powered document extraction)
  EXTRACTION_SERVICE_URL: z.string().default('http://localhost:4005'),

  // Rust runtime IPC — path to the cowork-orchestrator binary
  RUST_RUNTIME_BIN: z.string().default('cowork-orchestrator'),
  RUST_RUNTIME_TIMEOUT_MS: z.coerce.number().default(300_000),

  // Anthropic (passed through to Rust runtime)
  ANTHROPIC_API_KEY: z.string().optional(),

  // LLM Router — local Ollama support (H.7)
  OLLAMA_URL: z.string().default('http://localhost:11434/v1'),
  OLLAMA_MODELS: z.string().optional(),

  // Ecosystem toggles
  TELEMETRY_ENABLED: z.coerce.boolean().default(false),
  FEATURE_FLAGS_ENABLED: z.coerce.boolean().default(false),
});

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