# Knowledge Base Configuration Contracts (Schema Definitions)
#
# Pattern: Pure schema definitions using Nickel contracts
# Follows: provisioning/schemas pattern

{
  # === CORE TYPES ===

  GraphConfig = {
    name | String
      | doc "Graph name identifier",

    version | String
      | doc "Semantic version string"
      | default = "1.0.0",

    description | String
      | doc "Human-readable description"
      | default = "",
  },

  InheritanceConfig = {
    base | String
      | doc "Path to shared KOGRAL directory"
      | default = "/Users/Akasha/Tools/.kogral-shared",

    guidelines | Array String
      | doc "Additional guideline paths to inherit"
      | default = [],

    priority | Number
      | doc "Override priority (higher wins)"
      | default = 100,
  },

  # === STORAGE ===

  StorageType = [| 'filesystem, 'memory, 'surrealdb |],

  SecondaryStorageConfig = {
    enabled | Bool
      | doc "Enable secondary storage backend"
      | default = false,

    type | [| 'surrealdb, 'sqlite |]
      | doc "Secondary storage type"
      | default = 'surrealdb,

    url | String
      | doc "Connection URL"
      | default = "ws://localhost:8000",

    namespace | String
      | doc "SurrealDB namespace"
      | default = "kb",

    database | String
      | doc "SurrealDB database name"
      | default = "default",

    username | String
      | doc "Database username"
      | optional,

    password | String
      | doc "Database password"
      | optional,
  },

  StorageConfig = {
    primary | StorageType
      | doc "Primary storage backend"
      | default = 'filesystem,

    secondary | SecondaryStorageConfig
      | doc "Optional secondary storage"
      | default = { enabled = false },
  },

  # === EMBEDDINGS ===

  EmbeddingProviderType = [| 'openai, 'claude, 'ollama, 'fastembed |],

  EmbeddingConfig = {
    enabled | Bool
      | doc "Enable embedding generation"
      | default = true,

    provider | EmbeddingProviderType
      | doc "Embedding provider"
      | default = 'fastembed,

    model | String
      | doc "Model name/identifier"
      | default = "BAAI/bge-small-en-v1.5",

    dimensions | Number
      | doc "Embedding vector dimensions"
      | default = 384,

    api_key_env | String
      | doc "Environment variable for API key"
      | default = "OPENAI_API_KEY",
  },

  # === TEMPLATES ===

  DocumentTemplates = {
    note | String
      | default = "note.md.tera",

    decision | String
      | default = "decision.md.tera",

    guideline | String
      | default = "guideline.md.tera",

    pattern | String
      | default = "pattern.md.tera",

    journal | String
      | default = "journal.md.tera",

    execution | String
      | default = "execution.md.tera",
  },

  ExportTemplates = {
    logseq_page | String
      | default = "export/logseq-page.md.tera",

    logseq_journal | String
      | default = "export/logseq-journal.md.tera",

    summary | String
      | default = "export/summary.md.tera",

    json | String
      | default = "export/graph.json.tera",
  },

  TemplateConfig = {
    templates_dir | String
      | doc "Directory containing templates"
      | default = "templates",

    templates | DocumentTemplates
      | doc "Template files for each node type"
      | default = {},

    export | ExportTemplates
      | doc "Export format templates"
      | default = {},

    custom | { _ : String }
      | doc "Custom template registry (name → path)"
      | default = {},
  },

  # === QUERY ===

  QueryConfig = {
    similarity_threshold | Number
      | doc "Minimum similarity for semantic matches (0-1)"
      | default = 0.4,

    max_results | Number
      | doc "Maximum results to return"
      | default = 10,

    recency_weight | Number
      | doc "Weight factor for recent documents"
      | default = 3.0,

    cross_graph | Bool
      | doc "Enable cross-graph queries"
      | default = true,
  },

  # === MCP ===

  McpServerConfig = {
    name | String
      | default = "kogral-mcp",

    version | String
      | default = "1.0.0",

    transport | [| 'stdio, 'sse |]
      | default = 'stdio,
  },

  McpToolsConfig = {
    search | Bool | default = true,
    add_note | Bool | default = true,
    add_decision | Bool | default = true,
    link | Bool | default = true,
    get_guidelines | Bool | default = true,
    export | Bool | default = true,
  },

  McpResourcesConfig = {
    expose_project | Bool | default = true,
    expose_shared | Bool | default = true,
  },

  McpConfig = {
    server | McpServerConfig
      | default = {},

    tools | McpToolsConfig
      | default = {},

    resources | McpResourcesConfig
      | default = {},
  },

  # === SYNC ===

  SyncConfig = {
    auto_index | Bool
      | doc "Automatically sync filesystem to storage"
      | default = true,

    watch_paths | Array String
      | doc "Directories to watch for changes"
      | default = ["notes", "decisions", "guidelines", "patterns", "journal"],

    debounce_ms | Number
      | doc "Debounce delay for file system events"
      | default = 500,
  },

  # === MAIN CONFIG ===

  KbConfig = {
    graph | GraphConfig
      | doc "Graph metadata configuration",

    inheritance | InheritanceConfig
      | doc "Inheritance configuration"
      | default = {},

    storage | StorageConfig
      | doc "Storage backend configuration"
      | default = {},

    embeddings | EmbeddingConfig
      | doc "Embedding provider configuration"
      | default = {},

    templates | TemplateConfig
      | doc "Template system configuration"
      | default = {},

    query | QueryConfig
      | doc "Query engine configuration"
      | default = {},

    mcp | McpConfig
      | doc "MCP server configuration"
      | default = {},

    sync | SyncConfig
      | doc "Sync configuration"
      | default = {},
  },
}
