/**
 * 长期记忆 Provider 抽象层
 */

export type MemoryType = 'user' | 'project' | 'feedback' | 'reference' | (string & {});

export interface MemoryEntry {
  id: number;
  agentName: string;
  userId: string;
  type: MemoryType;
  name: string;
  content: string;
  description: string;
  metadata?: Record<string, unknown>;
  createdAt: Date;
  updatedAt: Date;
}

export interface MemorySearchOpts {
  agentName: string;
  userId?: string;   // 改为可选 — 管理页面跨用户查询
  type?: MemoryType;
  limit?: number;
}

export interface AgentMemoryConfig {
  enabled: boolean;
  backend: 'mysql' | 'sqlite';
  sqlitePath?: string;
  prefetchLimit?: number;
}

export interface MemoryPageOpts {
  agentName?: string;
  userId?: string;
  type?: MemoryType;
  keyWord?: string;
  page: number;
  size: number;
}

export interface MemoryCountOpts {
  agentName?: string;
  userId?: string;
  type?: MemoryType;
  keyWord?: string;
}

export interface MemoryPageResult {
  list: MemoryEntry[];
  pagination: { page: number; size: number; total: number };
}

export interface MemoryProvider {
  save(entry: Omit<MemoryEntry, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryEntry>;
  update(id: number, partial: Partial<Pick<MemoryEntry, 'name' | 'content' | 'description' | 'type' | 'metadata'>>): Promise<MemoryEntry>;
  delete(id: number): Promise<void>;
  search(query: string, opts: MemorySearchOpts): Promise<MemoryEntry[]>;
  list(opts: MemorySearchOpts): Promise<MemoryEntry[]>;
  getById(id: number): Promise<MemoryEntry | null>;
  close?(): Promise<void>;
  page(opts: MemoryPageOpts): Promise<MemoryPageResult>;
  count(opts: MemoryCountOpts): Promise<number>;
}
