/**
 * SQLite Interactive Message Repository Implementation
 *
 * Implements IInteractiveMessageRepository using SQLite database.
 * Uses prepared statements to prevent SQL injection.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { injectable } from 'tsyringe';
import { toDatabase, fromDatabase, } from '../persistence/sqlite/mappers/interactive-message.mapper.js';
const DEFAULT_MESSAGE_LIMIT = 200;
let SQLiteInteractiveMessageRepository = class SQLiteInteractiveMessageRepository {
    db;
    constructor(db) {
        this.db = db;
    }
    async create(message) {
        const row = toDatabase(message);
        this.db
            .prepare(`INSERT INTO interactive_messages
          (id, feature_id, session_id, role, content, step_id, created_at, updated_at)
         VALUES
          (@id, @feature_id, @session_id, @role, @content, @step_id, @created_at, @updated_at)`)
            .run(row);
    }
    async findByFeatureId(featureId, limit = DEFAULT_MESSAGE_LIMIT) {
        const rows = this.db
            .prepare(`SELECT * FROM interactive_messages
         WHERE feature_id = ?
         ORDER BY created_at ASC, rowid ASC
         LIMIT ?`)
            .all(featureId, limit);
        return rows.map(fromDatabase);
    }
    async findBySessionId(sessionId) {
        const rows = this.db
            .prepare(`SELECT * FROM interactive_messages
         WHERE session_id = ?
         ORDER BY created_at ASC, rowid ASC`)
            .all(sessionId);
        return rows.map(fromDatabase);
    }
    async deleteByFeatureId(featureId) {
        this.db.prepare(`DELETE FROM interactive_messages WHERE feature_id = ?`).run(featureId);
    }
};
SQLiteInteractiveMessageRepository = __decorate([
    injectable(),
    __metadata("design:paramtypes", [Object])
], SQLiteInteractiveMessageRepository);
export { SQLiteInteractiveMessageRepository };
