/**
 * Repository for filesystem watcher state (seq tracking per project).
 */
import { openDatabase } from "../database.js";
/**
 * Initializes the fs_state entry for a project with last_seq = 0.
 * No-op if the entry already exists.
 */
export function initFsState(projectId) {
    const db = openDatabase();
    db.prepare("INSERT OR IGNORE INTO fs_state (project_id, last_seq) VALUES (?, 0)").run(projectId);
}
/**
 * Gets the current seq number for a project.
 * Returns 0 if no entry exists.
 */
export function getSeq(projectId) {
    const db = openDatabase();
    const row = db.prepare("SELECT last_seq FROM fs_state WHERE project_id = ?").get(projectId);
    return row?.last_seq ?? 0;
}
/**
 * Updates the seq number for a project to a specific value.
 * Creates the entry if it doesn't exist.
 */
export function updateSeq(projectId, seq) {
    const db = openDatabase();
    db.prepare(`INSERT INTO fs_state (project_id, last_seq) VALUES (?, ?)
     ON CONFLICT (project_id) DO UPDATE SET last_seq = ?`).run(projectId, seq, seq);
}
/**
 * Increments and returns the next seq number for a project.
 * Creates the entry if it doesn't exist.
 */
export function incrementSeq(projectId) {
    const db = openDatabase();
    db.prepare(`INSERT INTO fs_state (project_id, last_seq) VALUES (?, 1)
     ON CONFLICT (project_id) DO UPDATE SET last_seq = last_seq + 1`).run(projectId);
    return getSeq(projectId);
}
/**
 * Resets the seq counter for a project.
 */
export function resetSeq(projectId) {
    const db = openDatabase();
    db.prepare("DELETE FROM fs_state WHERE project_id = ?").run(projectId);
}
//# sourceMappingURL=fs-state.js.map