/**
 * SQLite AgentGraphOverride Repository (spec 093, FR-38 ext)
 *
 * Backed by the agent_graph_overrides table (migration 099).
 */
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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe';
import { toDatabase, fromDatabase, } from '../persistence/sqlite/mappers/agent-graph-override.mapper.js';
let SQLiteAgentGraphOverrideRepository = class SQLiteAgentGraphOverrideRepository {
    db;
    constructor(db) {
        this.db = db;
    }
    async findActive(agentType) {
        const row = this.db
            .prepare('SELECT * FROM agent_graph_overrides WHERE agent_type = ? LIMIT 1')
            .get(agentType);
        return row ? fromDatabase(row) : null;
    }
    async listAll() {
        const rows = this.db
            .prepare('SELECT * FROM agent_graph_overrides ORDER BY agent_type ASC')
            .all();
        return rows.map(fromDatabase);
    }
    async create(override) {
        const row = toDatabase(override);
        this.db
            .prepare(`INSERT INTO agent_graph_overrides
         (id, agent_type, nodes_json, edges_json, version, created_by, created_at, updated_at)
         VALUES (@id, @agent_type, @nodes_json, @edges_json, @version, @created_by, @created_at, @updated_at)`)
            .run(row);
    }
    async update(override) {
        const row = toDatabase(override);
        this.db
            .prepare(`UPDATE agent_graph_overrides
            SET agent_type = @agent_type,
                nodes_json = @nodes_json,
                edges_json = @edges_json,
                version    = @version,
                created_by = @created_by,
                updated_at = @updated_at
          WHERE id = @id`)
            .run(row);
    }
    async delete(agentType) {
        this.db.prepare('DELETE FROM agent_graph_overrides WHERE agent_type = ?').run(agentType);
    }
};
SQLiteAgentGraphOverrideRepository = __decorate([
    injectable(),
    __param(0, inject('Database')),
    __metadata("design:paramtypes", [Object])
], SQLiteAgentGraphOverrideRepository);
export { SQLiteAgentGraphOverrideRepository };
