import { UserMemoryEntity, MemoryType } from '../entities/user-memory.entity';
import { SystemExperienceEntity, ExperienceType, VerificationStatus } from '../entities/system-experience.entity';

/**
 * 用户记忆仓储接口
 */
export interface IUserMemoryRepository {
  /** 保存用户记忆 */
  save(memory: UserMemoryEntity): Promise<void>;

  /** 根据ID获取记忆 */
  findById(id: string): Promise<UserMemoryEntity | null>;

  /** 获取用户所有记忆 */
  findByUserId(userId: string, options?: {
    memoryType?: MemoryType;
    includeExpired?: boolean;
    limit?: number;
  }): Promise<UserMemoryEntity[]>;

  /** 向量相似度搜索用户记忆 */
  searchByVector(userId: string, embedding: number[], options?: {
    memoryType?: MemoryType;
    limit?: number;
    minSimilarity?: number;
  }): Promise<Array<{ memory: UserMemoryEntity; similarity: number }>>;

  /** 获取用户最重要的记忆 */
  findTopMemories(userId: string, limit: number): Promise<UserMemoryEntity[]>;

  /** 更新记忆 */
  update(memory: UserMemoryEntity): Promise<void>;

  /** 删除记忆 */
  delete(id: string): Promise<void>;

  /** 删除用户所有记忆 */
  deleteByUserId(userId: string): Promise<void>;

  /** 标记用户过期的记忆 */
  markExpiredMemories(userId: string, olderThanDays: number): Promise<number>;
}

/**
 * 系统经验仓储接口
 */
export interface ISystemExperienceRepository {
  /** 保存系统经验 */
  save(experience: SystemExperienceEntity): Promise<void>;

  /** 根据ID获取经验 */
  findById(id: string): Promise<SystemExperienceEntity | null>;

  /** 获取待验证的经验 */
  findPendingExperiences(options?: {
    experienceType?: ExperienceType;
    limit?: number;
    offset?: number;
  }): Promise<SystemExperienceEntity[]>;

  /** 获取已激活的经验 */
  findActiveExperiences(options?: {
    experienceType?: ExperienceType;
    category?: string;
    minConfidence?: number;
    limit?: number;
  }): Promise<SystemExperienceEntity[]>;

  /** 向量相似度搜索经验 */
  searchByVector(embedding: number[], options?: {
    experienceType?: ExperienceType;
    activeOnly?: boolean;
    limit?: number;
    minSimilarity?: number;
  }): Promise<Array<{ experience: SystemExperienceEntity; similarity: number }>>;

  /** 查找相似经验（用于合并） */
  findSimilarExperiences(embedding: number[], threshold: number): Promise<SystemExperienceEntity[]>;

  /** 更新经验 */
  update(experience: SystemExperienceEntity): Promise<void>;

  /** 删除经验 */
  delete(id: string): Promise<void>;

  /** 获取统计数据 */
  getStatistics(): Promise<{
    total: number;
    byStatus: Record<VerificationStatus, number>;
    byType: Record<ExperienceType, number>;
  }>;
}

export const USER_MEMORY_REPOSITORY = Symbol('IUserMemoryRepository');
export const SYSTEM_EXPERIENCE_REPOSITORY = Symbol('ISystemExperienceRepository');
