/**
 * TCP: A.R.K.A. — mazgo konfigūracija.
 * Visi parametrai per aplinkos kintamuosius, kad mazgas veiktų „plug-and-play".
 * Configuration is read from environment variables so the node stays portable.
 */
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'

const __dirname = dirname(fileURLToPath(import.meta.url))

export const config = {
  /** HTTP prievadas / port (numatytai 8080). */
  port: Number(process.env.PORT ?? 8080),
  /** Localhost by default; opt in to LAN access with HOST=0.0.0.0. */
  host: process.env.HOST ?? '127.0.0.1',
  env: process.env.NODE_ENV ?? 'development',

  /** Nuoroda atgal į „The Cyber Prepper" portalą. */
  tcpUrl: process.env.ARKA_TCP_URL ?? 'https://thecyberprepper.com/',

  /**
   * Lokalus LLM. Suderinamas su Ollama, LM Studio, llama.cpp
   * (OpenAI-compatible /v1/chat/completions). Veikia be interneto.
   */
  ai: {
    baseUrl: process.env.ARKA_AI_BASE_URL ?? 'http://localhost:11434/v1',
    apiKey: process.env.ARKA_AI_KEY ?? 'arka-local',
    model: process.env.ARKA_AI_MODEL ?? 'llama3.2',
    timeoutMs: Number(process.env.ARKA_AI_TIMEOUT_MS ?? 30000),
  },

  /**
   * Lokali saugykla atsisiųstam turiniui (ZIM wiki, žemėlapiai).
   * Numatytai — `arka/storage`. Docker: /app/storage (per volume).
   */
  storagePath:
    process.env.ARKA_STORAGE_PATH ?? resolve(__dirname, '..', '..', 'storage'),

  /** ZIM pilno teksto indekso riba (maks. straipsnių). Apsauga nuo OOM. */
  zim: {
    maxIndexDocs: Number(process.env.ARKA_ZIM_MAX_DOCS ?? 1_000_000),
  },
} as const

export type Config = typeof config
