/**
 * ============================================================
 * Memory Type Definitions (메모리 타입 정의)
 * 
 * Astra의 5-Layer Cognitive Memory System의 모든 타입을 정의합니다.
 * ① Short-Term  ② Long-Term  ③ Project  ④ Procedural  ⑤ Episodic
 * ============================================================
 */

// ─── Common ───

export type MemoryLayer = 'short-term' | 'long-term' | 'project' | 'procedural' | 'episodic';

export interface MemoryContextResult {
    layer: MemoryLayer;
    label: string;
    content: string;
    relevance: number;  // 0.0 ~ 1.0
}

// ─── ① Short-Term Memory ───

export interface ShortTermMessage {
    role: 'user' | 'assistant' | 'system';
    content: string;
    timestamp: number;
}

// ─── ② Long-Term Memory ───

export type LongTermCategory = 'preference' | 'rule' | 'decision' | 'goal';

export interface LongTermEntry {
    id: string;
    category: LongTermCategory;
    content: string;
    source: string;              // 어떤 대화/세션에서 추출됐는지
    confidence: number;          // 0.0~1.0
    createdAt: number;
    lastReferencedAt: number;
    referenceCount: number;
}

export interface LongTermStore {
    version: number;
    entries: LongTermEntry[];
    lastUpdated: number;
}

// ─── ③ Project Memory ───

export interface ArchitectureDecision {
    id: string;
    title: string;
    decision: string;
    rationale: string;
    alternatives: string[];
    date: number;
}

export interface BugRecord {
    id: string;
    description: string;
    rootCause: string;
    fix: string;
    date: number;
    relatedFiles: string[];
}

export interface ProjectMemoryStore {
    version: number;
    projectId: string;          // workspace 경로 기반 hash
    projectName: string;
    techStack: string[];
    architectureDecisions: ArchitectureDecision[];
    bugRecords: BugRecord[];
    requirements: string[];
    designDirection: string;
    codeConventions: string[];
    lastUpdated: number;
}

// ─── ④ Procedural Memory ───

export interface ProceduralEntry {
    id: string;
    name: string;                   // "P-Reinforce Wikification"
    triggerPatterns: string[];       // ["wiki화", "위키", "wikify"]
    steps: string[];                // 순서대로 실행할 절차
    filePath: string;               // 실제 MD 파일 경로
    lastUsed: number;
    useCount: number;
}

// ─── ⑤ Episodic Memory ───

export interface EpisodicEntry {
    id: string;
    sessionId: string;
    title: string;                  // 자동 생성된 에피소드 제목
    summary: string;                // 대화 요약
    keyDecisions: string[];         // 주요 결정사항
    topics: string[];               // 주요 토픽 키워드
    projectContext?: string;        // 연관 프로젝트 경로
    timestamp: number;
    duration: number;               // 세션 길이 (ms)
    messageCount: number;
}

export interface EpisodicStore {
    version: number;
    episodes: EpisodicEntry[];
    lastUpdated: number;
}

// ─── Memory Manager Config ───

export interface MemoryConfig {
    enabled: boolean;
    shortTermLimit: number;
    longTermMaxEntries: number;
    episodicMaxEpisodes: number;
    projectMemoryEnabled: boolean;
    proceduralMemoryEnabled: boolean;
    episodicMemoryEnabled: boolean;
}
