"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../walls/06-memory/database/database");
const memory_event_store_1 = require("../walls/06-memory/stores/memory-event-store");
describe('Memory Event Store', () => {
    beforeAll(() => {
        (0, database_1.getDb)();
    });
    afterEach(() => {
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_events WHERE project = ?').run('test-project');
    });
    it('recordMemoryEvent returns id', () => {
        const id = (0, memory_event_store_1.recordMemoryEvent)({
            project: 'test-project',
            type: 'edit',
            summary: 'Test edit event',
            topic: 'test',
            importance: 5,
        });
        expect(id).toBeGreaterThan(0);
    });
    it('getMemoryEvents returns recorded events', () => {
        (0, memory_event_store_1.recordMemoryEvent)({
            project: 'test-project',
            type: 'decision',
            summary: 'Test decision',
            importance: 8,
        });
        const events = (0, memory_event_store_1.getMemoryEvents)({ project: 'test-project' });
        expect(events.length).toBeGreaterThanOrEqual(1);
        expect(events[0].type).toBe('decision');
        expect(events[0].summary).toBe('Test decision');
    });
    it('searchMemoryEvents finds by summary', () => {
        (0, memory_event_store_1.recordMemoryEvent)({
            project: 'test-project',
            type: 'error',
            summary: 'Database connection timeout',
            importance: 7,
        });
        const results = (0, memory_event_store_1.searchMemoryEvents)('timeout', 'test-project');
        expect(results.length).toBeGreaterThanOrEqual(1);
        expect(results[0].summary).toContain('timeout');
    });
    it('searchMemoryEvents finds by topic', () => {
        (0, memory_event_store_1.recordMemoryEvent)({
            project: 'test-project',
            type: 'fix',
            summary: 'Fixed the bug',
            topic: 'autostart',
            importance: 8,
        });
        const results = (0, memory_event_store_1.searchMemoryEvents)('autostart', 'test-project');
        expect(results.length).toBeGreaterThanOrEqual(1);
        expect(results[0].topic).toBe('autostart');
    });
    it('getMemoryEvents filters by type', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'edit', summary: 'Edit 1', importance: 3 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'error', summary: 'Error 1', importance: 7 });
        const edits = (0, memory_event_store_1.getMemoryEvents)({ project: 'test-project', type: 'edit' });
        expect(edits.every(e => e.importance !== undefined && e.type === 'edit')).toBe(true);
    });
    it('getMemoryEvents filters by minImportance', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'file_event', summary: 'Low', importance: 1 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'decision', summary: 'High', importance: 9 });
        const high = (0, memory_event_store_1.getMemoryEvents)({ project: 'test-project', minImportance: 7 });
        expect(high.every(e => (e.importance || 0) >= 7)).toBe(true);
    });
    it('recordMemoryEvents batch insert', () => {
        const ids = (0, memory_event_store_1.recordMemoryEvents)([
            { project: 'test-project', type: 'edit', summary: 'Batch 1', importance: 3 },
            { project: 'test-project', type: 'edit', summary: 'Batch 2', importance: 3 },
            { project: 'test-project', type: 'edit', summary: 'Batch 3', importance: 3 },
        ]);
        expect(ids.length).toBe(3);
        expect(ids.every(id => id > 0)).toBe(true);
    });
    it('getMemoryTimeline groups by date', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'edit', summary: 'Timeline test', importance: 3 });
        const timeline = (0, memory_event_store_1.getMemoryTimeline)('test-project', 7);
        expect(Array.isArray(timeline)).toBe(true);
        if (timeline.length > 0) {
            expect(timeline[0]).toHaveProperty('date');
            expect(timeline[0]).toHaveProperty('count');
            expect(timeline[0]).toHaveProperty('types');
        }
    });
    it('getMemoryStats returns counts', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'test-project', type: 'edit', summary: 'Stats test', importance: 5 });
        const stats = (0, memory_event_store_1.getMemoryStats)('test-project');
        expect(stats.total).toBeGreaterThanOrEqual(1);
        expect(stats.avgImportance).toBeGreaterThan(0);
        expect(stats.newestEvent).toBeTruthy();
    });
    it('deleteMemoryEventsOlderThan removes old events', () => {
        const deleted = (0, memory_event_store_1.deleteMemoryEventsOlderThan)(365);
        expect(typeof deleted).toBe('number');
    });
});
//# sourceMappingURL=memory-event-store.test.js.map