"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileChangesDAO = void 0; const uuid_1 = require("uuid"); class FileChangesDAO { dbManager; constructor(dbManager) { this.dbManager = dbManager; } get db() { return this.dbManager.getDatabase(); } create(input) { const id = input.id || (0, uuid_1.v4)(); const now = input.timestamp || new Date(); const change = { id, threadId: input.threadId, filePath: input.filePath, changeType: input.changeType, linesAdded: input.linesAdded || 0, linesDeleted: input.linesDeleted || 0, timestamp: now, gitCommit: input.gitCommit }; const stmt = this.db.prepare(` INSERT INTO file_changes ( id, thread_id, file_path, change_type, lines_added, lines_deleted, timestamp, git_commit ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? ) `); stmt.run(change.id, change.threadId, change.filePath, change.changeType, change.linesAdded, change.linesDeleted, change.timestamp.getTime(), change.gitCommit || null); // Update thread stats this.updateThreadStats(change.threadId); return change; } findByThreadId(threadId) { const stmt = this.db.prepare(` SELECT * FROM file_changes WHERE thread_id = ? ORDER BY timestamp DESC `); const rows = stmt.all(threadId); return rows.map(this.mapRowToFileChange); } updateThreadStats(threadId) { // Calculate aggregate stats const statsStmt = this.db.prepare(` SELECT COUNT(DISTINCT file_path) as files_changed, SUM(lines_added) as lines_added, SUM(lines_deleted) as lines_deleted FROM file_changes WHERE thread_id = ? `); const stats = statsStmt.get(threadId); const updateStmt = this.db.prepare(` UPDATE threads SET files_changed = ?, lines_added = ?, lines_deleted = ? WHERE id = ? `); updateStmt.run(stats.files_changed || 0, stats.lines_added || 0, stats.lines_deleted || 0, threadId); } mapRowToFileChange(row) { return { id: row.id, threadId: row.thread_id, filePath: row.file_path, changeType: row.change_type, linesAdded: row.lines_added, linesDeleted: row.lines_deleted, timestamp: new Date(row.timestamp), gitCommit: row.git_commit || undefined }; } } exports.FileChangesDAO = FileChangesDAO;