/**
 * SQLite AgentPromptOverride Repository (spec 093, FR-34)
 *
 * Backed by the agent_prompt_overrides table (migration 098).
 */
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-prompt-override.mapper.js';
let SQLiteAgentPromptOverrideRepository = class SQLiteAgentPromptOverrideRepository {
    db;
    constructor(db) {
        this.db = db;
    }
    async findActive(agentType, promptId) {
        const row = this.db
            .prepare('SELECT * FROM agent_prompt_overrides WHERE agent_type = ? AND prompt_id = ? LIMIT 1')
            .get(agentType, promptId);
        return row ? fromDatabase(row) : null;
    }
    async listForAgent(agentType) {
        const rows = this.db
            .prepare('SELECT * FROM agent_prompt_overrides WHERE agent_type = ? ORDER BY prompt_id ASC')
            .all(agentType);
        return rows.map(fromDatabase);
    }
    async listAll() {
        const rows = this.db
            .prepare('SELECT * FROM agent_prompt_overrides ORDER BY agent_type ASC, prompt_id ASC')
            .all();
        return rows.map(fromDatabase);
    }
    async create(override) {
        const row = toDatabase(override);
        this.db
            .prepare(`INSERT INTO agent_prompt_overrides
         (id, agent_type, prompt_id, body, version, created_by, created_at, updated_at)
         VALUES (@id, @agent_type, @prompt_id, @body, @version, @created_by, @created_at, @updated_at)`)
            .run(row);
    }
    async update(override) {
        const row = toDatabase(override);
        this.db
            .prepare(`UPDATE agent_prompt_overrides
            SET agent_type = @agent_type,
                prompt_id  = @prompt_id,
                body       = @body,
                version    = @version,
                created_by = @created_by,
                updated_at = @updated_at
          WHERE id = @id`)
            .run(row);
    }
    async delete(agentType, promptId) {
        this.db
            .prepare('DELETE FROM agent_prompt_overrides WHERE agent_type = ? AND prompt_id = ?')
            .run(agentType, promptId);
    }
};
SQLiteAgentPromptOverrideRepository = __decorate([
    injectable(),
    __param(0, inject('Database')),
    __metadata("design:paramtypes", [Object])
], SQLiteAgentPromptOverrideRepository);
export { SQLiteAgentPromptOverrideRepository };
