import { KnowledgeArticleEntity } from '../entities/knowledge-article.entity';
import { KnowledgeChunkEntity } from '../entities/knowledge-chunk.entity';

/**
 * 知识库仓储接口
 */
export interface IKnowledgeRepository {
  // ========== 文章操作 ==========

  /** 保存文章 */
  saveArticle(article: KnowledgeArticleEntity): Promise<void>;

  /** 根据ID获取文章 */
  findArticleById(id: string): Promise<KnowledgeArticleEntity | null>;

  /** 根据类别获取文章列表 */
  findArticlesByCategory(category: string, options?: {
    publishedOnly?: boolean;
    limit?: number;
    offset?: number;
  }): Promise<KnowledgeArticleEntity[]>;

  /** 搜索文章（关键词） */
  searchArticles(query: string, options?: {
    category?: string;
    publishedOnly?: boolean;
    limit?: number;
  }): Promise<KnowledgeArticleEntity[]>;

  /** 向量相似度搜索文章 */
  searchArticlesByVector(embedding: number[], options?: {
    category?: string;
    publishedOnly?: boolean;
    limit?: number;
    minSimilarity?: number;
  }): Promise<Array<{ article: KnowledgeArticleEntity; similarity: number }>>;

  /** 更新文章 */
  updateArticle(article: KnowledgeArticleEntity): Promise<void>;

  /** 删除文章 */
  deleteArticle(id: string): Promise<void>;

  /** 获取文章总数 */
  countArticles(options?: {
    category?: string;
    publishedOnly?: boolean;
  }): Promise<number>;

  // ========== 块操作 ==========

  /** 保存知识块 */
  saveChunk(chunk: KnowledgeChunkEntity): Promise<void>;

  /** 批量保存知识块 */
  saveChunks(chunks: KnowledgeChunkEntity[]): Promise<void>;

  /** 根据文章ID获取所有块 */
  findChunksByArticleId(articleId: string): Promise<KnowledgeChunkEntity[]>;

  /** 向量相似度搜索块 */
  searchChunksByVector(embedding: number[], options?: {
    category?: string;
    limit?: number;
    minSimilarity?: number;
  }): Promise<Array<{ chunk: KnowledgeChunkEntity; similarity: number }>>;

  /** 删除文章的所有块 */
  deleteChunksByArticleId(articleId: string): Promise<void>;
}

export const KNOWLEDGE_REPOSITORY = Symbol('IKnowledgeRepository');
