/**
 * SQLite CustomAgent Repository (spec 093, FR-39 ext)
 *
 * Backed by the custom_agents table (migration 100).
 */
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/custom-agent.mapper.js';
let SQLiteCustomAgentRepository = class SQLiteCustomAgentRepository {
    db;
    constructor(db) {
        this.db = db;
    }
    async findByType(agentType) {
        const row = this.db
            .prepare('SELECT * FROM custom_agents WHERE agent_type = ? LIMIT 1')
            .get(agentType);
        return row ? fromDatabase(row) : null;
    }
    async listAll() {
        const rows = this.db
            .prepare('SELECT * FROM custom_agents ORDER BY agent_type ASC')
            .all();
        return rows.map(fromDatabase);
    }
    async create(agent) {
        const row = toDatabase(agent);
        this.db
            .prepare(`INSERT INTO custom_agents
         (id, agent_type, name, description, created_by, created_at, updated_at)
         VALUES (@id, @agent_type, @name, @description, @created_by, @created_at, @updated_at)`)
            .run(row);
    }
    async update(agent) {
        const row = toDatabase(agent);
        this.db
            .prepare(`UPDATE custom_agents
            SET agent_type  = @agent_type,
                name        = @name,
                description = @description,
                created_by  = @created_by,
                updated_at  = @updated_at
          WHERE id = @id`)
            .run(row);
    }
    async delete(agentType) {
        this.db.prepare('DELETE FROM custom_agents WHERE agent_type = ?').run(agentType);
    }
};
SQLiteCustomAgentRepository = __decorate([
    injectable(),
    __param(0, inject('Database')),
    __metadata("design:paramtypes", [Object])
], SQLiteCustomAgentRepository);
export { SQLiteCustomAgentRepository };
