/**
 * In-Memory CustomAgent Repository
 *
 * Test-friendly adapter for {@link ICustomAgentRepository}.
 */
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';
let InMemoryCustomAgentRepository = class InMemoryCustomAgentRepository {
    byId = new Map();
    byType = new Map();
    async findByType(agentType) {
        const id = this.byType.get(agentType);
        if (!id)
            return null;
        const row = this.byId.get(id);
        return row ? { ...row } : null;
    }
    async listAll() {
        return [...this.byId.values()]
            .map((row) => ({ ...row }))
            .sort((a, b) => a.agentType.localeCompare(b.agentType));
    }
    async create(agent) {
        if (this.byId.has(agent.id)) {
            throw new Error(`CustomAgent with id "${agent.id}" already exists`);
        }
        if (this.byType.has(agent.agentType)) {
            throw new Error(`CustomAgent already exists for agentType=${agent.agentType}`);
        }
        this.byId.set(agent.id, { ...agent });
        this.byType.set(agent.agentType, agent.id);
    }
    async update(agent) {
        if (!this.byId.has(agent.id)) {
            throw new Error(`CustomAgent with id "${agent.id}" not found`);
        }
        this.byId.set(agent.id, { ...agent });
        this.byType.set(agent.agentType, agent.id);
    }
    async delete(agentType) {
        const id = this.byType.get(agentType);
        if (!id)
            return;
        this.byType.delete(agentType);
        this.byId.delete(id);
    }
};
InMemoryCustomAgentRepository = __decorate([
    injectable()
], InMemoryCustomAgentRepository);
export { InMemoryCustomAgentRepository };
