/**
 * Types for AlloyDB vector memory (knowledge_chunks table)
 */

/**
 * A semantic chunk of a knowledge_item with vector embedding
 */
export interface KnowledgeChunk {
  /** UUID primary key */
  id: string;
  
  /** Firestore project ID */
  projectId: string;
  
  /** Firestore knowledge_item ID */
  knowledgeItemId: string;
  
  /** Index of this chunk within the parent knowledge_item (0-based) */
  chunkIndex: number;
  
  /** Text content of this chunk */
  content: string;
  
  /** Source type (e.g., 'imported_ai_chat', 'imported_document', etc.) */
  sourceType: string | null;
  
  /** Importance classification (for filtering) */
  importance: 'primary' | 'supporting' | 'irrelevant' | null;
  
  /** When this chunk was created */
  createdAt: string;
  
  /** When this chunk was last updated */
  updatedAt: string;
}

/**
 * Database row shape (snake_case from PostgreSQL)
 */
export interface KnowledgeChunkRow {
  id: string;
  project_id: string;
  knowledge_item_id: string;
  chunk_index: number;
  content: string;
  source_type: string | null;
  importance: 'primary' | 'supporting' | 'irrelevant' | null;
  created_at: string;
  updated_at: string;
}

/**
 * Result of a vector similarity search, includes similarity score
 */
export interface KnowledgeChunkSearchResult extends KnowledgeChunk {
  /** Similarity score (0-1, higher = more similar) */
  similarity: number;
}

/**
 * Options for vector search
 */
export interface VectorSearchOptions {
  /** Maximum number of results to return */
  limit?: number;
  
  /** Minimum similarity threshold (0-1) */
  minSimilarity?: number;
  
  /** Filter by source type(s) */
  sourceTypes?: string[];
  
  /** Filter by importance level(s) */
  importanceLevels?: ('primary' | 'supporting' | 'irrelevant')[];
  
  /** Whether to include embedding in results (default: false) */
  includeEmbedding?: boolean;
}

/**
 * Input for creating a new knowledge chunk
 */
export interface CreateKnowledgeChunkInput {
  projectId: string;
  knowledgeItemId: string;
  chunkIndex: number;
  content: string;
  embedding: number[];
  sourceType?: string | null;
  importance?: 'primary' | 'supporting' | 'irrelevant' | null;
}

/**
 * Batch input for creating multiple chunks at once
 */
export interface BatchCreateKnowledgeChunksInput {
  projectId: string;
  knowledgeItemId: string;
  chunks: {
    chunkIndex: number;
    content: string;
    embedding: number[];
    sourceType?: string | null;
    importance?: 'primary' | 'supporting' | 'irrelevant' | null;
  }[];
}

