/**
 * SQLite Page Version Repository Implementation
 *
 * Implements IPageVersionRepository using better-sqlite3.
 * Tracks version history for wiki-style page content.
 */
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/page-version.mapper.js';
let SQLitePageVersionRepository = class SQLitePageVersionRepository {
    db;
    constructor(db) {
        this.db = db;
    }
    async create(version) {
        const row = toDatabase(version);
        const stmt = this.db.prepare(`
      INSERT INTO page_versions (
        id, page_id, version_number, title, content,
        created_at, updated_at
      ) VALUES (
        @id, @page_id, @version_number, @title, @content,
        @created_at, @updated_at
      )
    `);
        stmt.run(row);
    }
    async listByPage(pageId) {
        const stmt = this.db.prepare('SELECT * FROM page_versions WHERE page_id = ? ORDER BY version_number DESC');
        const rows = stmt.all(pageId);
        return rows.map(fromDatabase);
    }
    async findLatest(pageId) {
        const stmt = this.db.prepare('SELECT * FROM page_versions WHERE page_id = ? ORDER BY version_number DESC LIMIT 1');
        const row = stmt.get(pageId);
        return row ? fromDatabase(row) : null;
    }
    async findByVersion(pageId, versionNumber) {
        const stmt = this.db.prepare('SELECT * FROM page_versions WHERE page_id = ? AND version_number = ?');
        const row = stmt.get(pageId, versionNumber);
        return row ? fromDatabase(row) : null;
    }
};
SQLitePageVersionRepository = __decorate([
    injectable(),
    __metadata("design:paramtypes", [Object])
], SQLitePageVersionRepository);
export { SQLitePageVersionRepository };
