export class QAService {
    db;
    constructor(db) {
        this.db = db;
    }
    logEntry(topicId, kind, content, sessionId, questionId) {
        const result = this.db.raw
            .prepare('INSERT INTO entries (topic_id, kind, content, session_id, question_id) VALUES (?, ?, ?, ?, ?) RETURNING id')
            .get(topicId, kind, content, sessionId ?? '', questionId ?? null);
        return this.db.raw
            .prepare('SELECT * FROM entries WHERE id = ?')
            .get(result.id);
    }
    listEntries(topicId) {
        return this.db.raw
            .prepare('SELECT * FROM entries WHERE topic_id = ? ORDER BY created_at ASC')
            .all(topicId);
    }
    search(query) {
        return this.db.raw
            .prepare(`SELECT e.id, e.topic_id, e.kind, e.content, e.created_at
         FROM entries e
         JOIN entries_fts ON entries_fts.rowid = e.id
         WHERE entries_fts MATCH ?
         ORDER BY e.created_at ASC
         LIMIT 50`)
            .all(query);
    }
}
//# sourceMappingURL=qa.js.map