/**
 * ============================================================================
 * LANGCHAIN CONFIGURATION PRESET
 * ============================================================================
 *
 * This is a preset template for LangChain plugin configuration.
 * Copy this file to your theme's lib/langchain/langchain.config.ts
 *
 * Path: contents/themes/{your-theme}/lib/langchain/langchain.config.ts
 *
 * ============================================================================
 */

import type { ObservabilityConfig } from '@/contents/plugins/langchain/types/observability.types'
import type {
  ThemeLangChainConfig,
  AgentDefinition,
  AgentContext,
} from '@/contents/plugins/langchain/types/langchain.types'
import { createAgentHelpers } from '@/contents/plugins/langchain/lib/agent-helpers'

// TODO: Import your tool factories
// import { createTaskTools } from './tools/tasks'
// import { createCustomerTools } from './tools/customers'

// ============================================================================
// OBSERVABILITY CONFIGURATION
// ============================================================================

export interface LangChainObservabilityConfig {
  /** Observability configuration */
  observability: ObservabilityConfig
}

export const observabilityConfig: LangChainObservabilityConfig = {
  observability: {
    /** Enable observability tracing */
    enabled: true,

    /** Data retention settings */
    retention: {
      /** Days to keep trace data */
      traces: 30,
    },

    /** Sampling configuration */
    sampling: {
      /** Sample rate (0.0-1.0) - 1.0 = 100% */
      rate: 1.0,
      /** Always trace errors regardless of sample rate */
      alwaysTraceErrors: true,
    },

    /** PII and content processing */
    pii: {
      /** Mask inputs for PII (email, phone, card, SSN patterns) */
      maskInputs: false,
      /** Mask outputs for PII */
      maskOutputs: false,
      /** Truncate content at this length (characters) */
      truncateAt: 10000,
    },
  },
}

// ============================================================================
// AGENT DEFINITIONS
// ============================================================================

/**
 * Define your agents here.
 *
 * Each agent has:
 * - provider: LLM provider (ollama, openai, anthropic)
 * - model: Model name (optional for ollama - uses LANGCHAIN_OLLAMA_MODEL env)
 * - temperature: Creativity level (0-1)
 * - createTools: Factory function that returns tools for this agent
 * - systemPrompt: Name of the .md file in lib/langchain/agents/ folder
 * - description: What this agent does (documentation)
 * - sessionConfig: (optional) Memory customization (TTL, maxMessages)
 * - enrichContext: (optional) Fetch runtime data for prompt templates
 */
export const AGENTS: Record<string, AgentDefinition> = {
  // Example: Single unified agent
  'single-agent': {
    provider: 'ollama',
    // model: uses LANGCHAIN_OLLAMA_MODEL from .env
    temperature: 0.3,
    description: 'Unified agent with access to all entity tools',
    systemPrompt: 'single-agent', // loads from lib/langchain/agents/single-agent.md
    createTools: (context: AgentContext) => [
      // TODO: Add your tools here
      // ...createTaskTools(context),
    ],
  },

  // Example: Orchestrator for multi-agent routing
  // 'orchestrator': {
  //   provider: 'anthropic',
  //   model: 'claude-3-haiku-20240307',
  //   temperature: 0.1,
  //   description: 'Routes to specialized agents',
  //   systemPrompt: 'orchestrator',
  //   createTools: () => createOrchestratorTools(),
  // },
}

// ============================================================================
// THEME CONFIG (for plugin compatibility)
// ============================================================================

export const langchainConfig: ThemeLangChainConfig = {
  defaultProvider: 'ollama',
  defaultTemperature: 0.3,
  agents: AGENTS,
}

// ============================================================================
// HELPERS (from plugin factory)
// ============================================================================

/**
 * Helper functions created from the plugin's factory.
 * These provide convenient access to agent configuration.
 */
const helpers = createAgentHelpers(AGENTS, {
  provider: langchainConfig.defaultProvider,
  model: langchainConfig.defaultModel,
  temperature: langchainConfig.defaultTemperature,
})

// Re-export individual helpers for convenience
export const {
  getAgentConfig,
  getAgentModelConfig,
  getAgentTools,
  getAgentPromptName,
  getAgentSessionConfig,
  getAgentEnrichContext,
  hasAgent,
  getAgentNames,
} = helpers
