/**
 * In-Memory AgentPromptOverride Repository
 *
 * Test-friendly adapter for {@link IAgentPromptOverrideRepository}.
 * Enforces the unique-(agentType, promptId) constraint locally so tests
 * exercise the same invariant the SQLite adapter enforces.
 */
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;
};
import { injectable } from 'tsyringe';
function key(agentType, promptId) {
    return `${agentType}::${promptId}`;
}
let InMemoryAgentPromptOverrideRepository = class InMemoryAgentPromptOverrideRepository {
    byId = new Map();
    bySlot = new Map();
    async findActive(agentType, promptId) {
        const id = this.bySlot.get(key(agentType, promptId));
        if (!id)
            return null;
        const row = this.byId.get(id);
        return row ? { ...row } : null;
    }
    async listForAgent(agentType) {
        return [...this.byId.values()]
            .filter((row) => row.agentType === agentType)
            .map((row) => ({ ...row }))
            .sort((a, b) => a.promptId.localeCompare(b.promptId));
    }
    async listAll() {
        return [...this.byId.values()]
            .map((row) => ({ ...row }))
            .sort((a, b) => {
            if (a.agentType !== b.agentType)
                return a.agentType.localeCompare(b.agentType);
            return a.promptId.localeCompare(b.promptId);
        });
    }
    async create(override) {
        if (this.byId.has(override.id)) {
            throw new Error(`AgentPromptOverride with id "${override.id}" already exists`);
        }
        const slotKey = key(override.agentType, override.promptId);
        if (this.bySlot.has(slotKey)) {
            throw new Error(`AgentPromptOverride already exists for agentType=${override.agentType}, promptId=${override.promptId}`);
        }
        this.byId.set(override.id, { ...override });
        this.bySlot.set(slotKey, override.id);
    }
    async update(override) {
        if (!this.byId.has(override.id)) {
            throw new Error(`AgentPromptOverride with id "${override.id}" not found`);
        }
        this.byId.set(override.id, { ...override });
        this.bySlot.set(key(override.agentType, override.promptId), override.id);
    }
    async delete(agentType, promptId) {
        const slotKey = key(agentType, promptId);
        const id = this.bySlot.get(slotKey);
        if (!id)
            return;
        this.bySlot.delete(slotKey);
        this.byId.delete(id);
    }
};
InMemoryAgentPromptOverrideRepository = __decorate([
    injectable()
], InMemoryAgentPromptOverrideRepository);
export { InMemoryAgentPromptOverrideRepository };
