import { generateMemoryId } from '../../utils/id.js';
import { InMemoryMemoryIndex } from './index.js';
export class InMemoryMemoryStore {
    content = new Map();
    index = new InMemoryMemoryIndex();
    async create(params) {
        const id = generateMemoryId();
        const now = Date.now();
        const entry = {
            id,
            title: params.title,
            summary: params.summary,
            tags: params.tags ? [...params.tags] : [],
            status: 'active',
            createdAt: now,
            updatedAt: now,
        };
        const memoryContent = {
            id,
            content: params.content,
            format: params.format ?? 'text',
            metadata: params.metadata ? { ...params.metadata } : undefined,
        };
        this.index.set(entry);
        this.content.set(id, memoryContent);
        return { entry, content: memoryContent };
    }
    async get(id) {
        return this.content.get(id);
    }
    async update(id, updates) {
        const existing = this.index.getEntry(id);
        if (!existing)
            return undefined;
        const now = Date.now();
        const updated = {
            ...existing,
            title: updates.title ?? existing.title,
            summary: updates.summary ?? existing.summary,
            tags: updates.tags ? [...updates.tags] : existing.tags,
            updatedAt: now,
        };
        this.index.set(updated);
        if (updates.content !== undefined ||
            updates.format !== undefined ||
            updates.metadata !== undefined) {
            const existingContent = this.content.get(id);
            if (existingContent) {
                const updatedContent = {
                    ...existingContent,
                    content: updates.content ?? existingContent.content,
                    format: updates.format ?? existingContent.format,
                    metadata: updates.metadata !== undefined ? { ...updates.metadata } : existingContent.metadata,
                };
                this.content.set(id, updatedContent);
            }
        }
        return updated;
    }
    async delete(id) {
        const existed = this.index.remove(id);
        this.content.delete(id);
        return existed;
    }
    async list(params) {
        return this.index.search(params ?? {});
    }
    getIndex() {
        return this.index;
    }
}
//# sourceMappingURL=memory.js.map