/**
 * Familiar Memory System Types
 * 
 * This system provides persistent memory and cross-agent knowledge sharing
 * for all 13 Foundry agents. It mirrors the Tesa Memory architecture but is
 * optimized for multi-agent collaboration.
 */

export type MemoryCategory = 
  | 'decision'
  | 'observation'
  | 'pattern'
  | 'rule'
  | 'fact'
  | 'preference'
  | 'relationship'
  | 'anomaly'
  | 'escalation'
  | 'outcome';

export type InsightType = 
  | 'pattern'
  | 'anomaly'
  | 'recommendation'
  | 'warning'
  | 'opportunity'
  | 'prediction';

export type InsightSeverity = 'info' | 'warning' | 'critical';
export type InsightStatus = 'pending' | 'acknowledged' | 'actioned' | 'dismissed';

export interface AgentMemoryEntry {
  id: string;
  agentId: string;
  category: MemoryCategory;
  key: string;
  content: any;
  confidence: number;
  accessCount: number;
  importance: number;
  source?: string;
  expiresAt?: Date;
  createdAt: Date;
  updatedAt: Date;
}

export interface SharedMemoryEntry {
  id: string;
  category: string;
  key: string;
  value: any;
  confidence: number;
  source?: string;
  usageCount: number;
  lastUsed?: Date;
  expiresAt?: Date;
  createdAt: Date;
  updatedAt: Date;
}

export interface AgentInsightEntry {
  id: string;
  agentId: string;
  type: InsightType;
  title: string;
  content: string;
  severity: InsightSeverity;
  confidence: number;
  actionable: boolean;
  relatedData: any;
  tags: string[];
  status: InsightStatus;
  acknowledgedBy?: string;
  acknowledgedAt?: Date;
  actionTaken?: string;
  createdAt: Date;
  updatedAt: Date;
}

export interface AgentInteractionEntry {
  id: string;
  fromAgentId: string;
  toAgentId: string;
  type: 'query' | 'escalation' | 'notification' | 'delegation';
  priority: 'low' | 'normal' | 'high' | 'urgent';
  subject: string;
  content: any;
  response?: any;
  status: 'pending' | 'in_progress' | 'completed' | 'escalated';
  escalatedTo?: string;
  completedAt?: Date;
  responseTimeMs?: number;
  metadata: any;
  createdAt: Date;
}

export interface MemoryQueryOptions {
  agentId?: string;
  category?: MemoryCategory | MemoryCategory[];
  search?: string;
  minImportance?: number;
  minConfidence?: number;
  tags?: string[];
  includeExpired?: boolean;
  limit?: number;
  offset?: number;
  orderBy?: 'importance' | 'confidence' | 'createdAt' | 'accessCount';
  orderDir?: 'asc' | 'desc';
}

export interface InsightQueryOptions {
  agentId?: string;
  type?: InsightType | InsightType[];
  severity?: InsightSeverity | InsightSeverity[];
  status?: InsightStatus | InsightStatus[];
  actionable?: boolean;
  limit?: number;
  offset?: number;
}

export interface CrossAgentQuery {
  query: string;
  fromAgentId: string;
  targetAgents?: string[];
  context?: any;
  requiresResponse?: boolean;
}

export interface MemorySystemConfig {
  id: string;
  organizationId: string;
  enabled: boolean;
  retentionDays: number;
  maxMemoriesPerAgent: number;
  maxInsightsPerDay: number;
  autoCleanupEnabled: boolean;
  crossAgentSharingEnabled: boolean;
  mcpEndpointEnabled: boolean;
  llmInsightsEnabled: boolean;
  proactiveAlertsEnabled: boolean;
  sensitiveDataFiltering: boolean;
  auditLogging: boolean;
  customRules: any[];
}
