export class InMemoryMemoryIndex {
    entries = new Map();
    search(params) {
        let results = Array.from(this.entries.values());
        if (params.query) {
            const q = params.query.toLowerCase();
            results = results.filter((e) => e.title.toLowerCase().includes(q) || e.summary.toLowerCase().includes(q));
        }
        if (params.tags && params.tags.length > 0) {
            const requiredTags = params.tags;
            results = results.filter((e) => requiredTags.every((tag) => e.tags.includes(tag)));
        }
        if (params.status) {
            results = results.filter((e) => e.status === params.status);
        }
        results.sort((a, b) => b.updatedAt - a.updatedAt);
        const totalCount = results.length;
        const limit = params.limit ?? totalCount;
        return {
            entries: results.slice(0, limit),
            totalCount,
        };
    }
    getEntry(id) {
        return this.entries.get(id);
    }
    allEntries() {
        return Array.from(this.entries.values());
    }
    count() {
        return this.entries.size;
    }
    rebuild(entries) {
        this.entries.clear();
        for (const entry of entries) {
            this.entries.set(entry.id, entry);
        }
    }
    set(entry) {
        this.entries.set(entry.id, entry);
    }
    remove(id) {
        return this.entries.delete(id);
    }
}
//# sourceMappingURL=index.js.map