/**
 * Database Integration Layer
 *
 * Provides a unified interface for integrating the SQLite database
 * with existing components. This module bridges the old JSON-based
 * storage with the new database system.
 */
import { EventEmitter } from 'events';
import { getDatabaseManager } from './database-manager.js';
import { getMemoryRepository, type MemoryFilter } from './repositories/memory-repository.js';
import { getSessionRepository } from './repositories/session-repository.js';
import { getEmbeddingRepository } from './repositories/embedding-repository.js';
import { getCacheRepository } from './repositories/cache-repository.js';
import type { Memory, MemoryType, Session, Message } from './schema.js';
export interface DatabaseIntegrationConfig {
    dbPath?: string;
    inMemory?: boolean;
    autoMigrate?: boolean;
    embeddingProvider?: 'local' | 'openai' | 'grok' | 'mock';
}
export interface MemoryAddOptions {
    type: MemoryType;
    scope?: 'user' | 'project';
    projectId?: string;
    importance?: number;
    expiresAt?: Date;
    metadata?: Record<string, unknown>;
    generateEmbedding?: boolean;
}
export interface MemorySearchOptions {
    type?: MemoryType | MemoryType[];
    scope?: 'user' | 'project';
    projectId?: string;
    minImportance?: number;
    limit?: number;
    semantic?: boolean;
}
export declare class DatabaseIntegration extends EventEmitter {
    private initialized;
    private config;
    constructor(config?: DatabaseIntegrationConfig);
    /**
     * Initialize the database system
     */
    initialize(): Promise<void>;
    /**
     * Check if initialized
     */
    isInitialized(): boolean;
    /**
     * Add a memory
     */
    addMemory(content: string, options: MemoryAddOptions): Promise<Memory>;
    /**
     * Search memories
     */
    searchMemories(query: string, options?: MemorySearchOptions): Promise<{
        memory: Memory;
        similarity?: number;
    }[]>;
    /**
     * Get memories by filter
     */
    getMemories(filter?: MemoryFilter): Memory[];
    /**
     * Update memory importance
     */
    updateMemoryImportance(id: string, importance: number): boolean;
    /**
     * Delete memory
     */
    deleteMemory(id: string): boolean;
    /**
     * Create a new session
     */
    createSession(options?: {
        projectId?: string;
        projectPath?: string;
        name?: string;
        model?: string;
    }): Session;
    /**
     * Get session by ID
     */
    getSession(id: string): Session | null;
    /**
     * Add message to session
     */
    addMessage(sessionId: string, role: 'user' | 'assistant' | 'system' | 'tool', content?: string, options?: {
        toolCalls?: unknown[];
        toolCallId?: string;
        tokens?: number;
    }): Message;
    /**
     * Get messages for session
     */
    getMessages(sessionId: string, limit?: number): Message[];
    /**
     * Update session stats
     */
    updateSessionStats(sessionId: string, stats: {
        tokensIn?: number;
        tokensOut?: number;
        cost?: number;
        toolCalls?: number;
    }): void;
    /**
     * Get recent sessions
     */
    getRecentSessions(limit?: number): Session[];
    /**
     * Record repair attempt
     */
    recordRepairAttempt(errorMessage: string, errorType: 'compile' | 'runtime' | 'test' | 'lint' | 'type', strategy: string, success: boolean, attempts: number, options?: {
        language?: string;
        framework?: string;
        fixCode?: string;
    }): void;
    /**
     * Get best repair strategies
     */
    getBestRepairStrategies(errorMessage: string, options?: {
        errorType?: 'compile' | 'runtime' | 'test' | 'lint' | 'type';
        language?: string;
        limit?: number;
    }): {
        strategy: string;
        successRate: number;
    }[];
    /**
     * Record tool usage
     */
    recordToolUsage(toolName: string, success: boolean, timeMs: number, cacheHit: boolean, projectId?: string): void;
    /**
     * Get cost summary
     */
    getCostSummary(): {
        session: number;
        daily: number;
        weekly: number;
        monthly: number;
    };
    /**
     * Get analytics dashboard
     */
    getAnalyticsDashboard(): string;
    /**
     * Get learning stats
     */
    getLearningStats(): string;
    /**
     * Get cached value
     */
    getCached<T>(key: string): T | null;
    /**
     * Set cached value
     */
    setCached<T>(key: string, value: T, ttlMs?: number): void;
    /**
     * Get or compute cached value
     */
    getOrComputeCached<T>(key: string, computeFn: () => Promise<T>, ttlMs?: number): Promise<T>;
    /**
     * Index code chunk
     */
    indexCodeChunk(projectId: string, filePath: string, chunkIndex: number, chunkText: string, options?: {
        symbolType?: string;
        symbolName?: string;
        startLine?: number;
        endLine?: number;
        language?: string;
    }): Promise<void>;
    /**
     * Search code semantically
     */
    searchCode(query: string, projectId: string, options?: {
        limit?: number;
        symbolType?: string;
    }): Promise<{
        filePath: string;
        chunkText: string;
        similarity: number;
    }[]>;
    /**
     * Get database statistics
     */
    getStats(): {
        database: ReturnType<typeof getDatabaseManager.prototype.getStats>;
        memory: ReturnType<typeof getMemoryRepository.prototype.getStats>;
        session: ReturnType<typeof getSessionRepository.prototype.getStats>;
        embedding: ReturnType<typeof getEmbeddingRepository.prototype.getStats>;
        cache: ReturnType<typeof getCacheRepository.prototype.getStats>;
    };
    /**
     * Format stats for display
     */
    formatStats(): string;
    private generateId;
    private hashString;
}
export declare function getDatabaseIntegration(config?: DatabaseIntegrationConfig): DatabaseIntegration;
export declare function initializeDatabaseIntegration(config?: DatabaseIntegrationConfig): Promise<DatabaseIntegration>;
export declare function resetDatabaseIntegration(): void;
