/**
 * HITL approval-channel contract + in-memory store.
 *
 * Transport-agnostic: concrete transports live in concrete channel
 * implementations (email, telegram, etc.).
 */
/**
 * Process-local in-memory store. Suitable for CI tests and single-instance
 * deployments. Multi-instance prod deployments should plug a Redis/Postgres
 * impl behind this interface.
 */
export class InMemoryApprovalStore {
    entries = new Map();
    async create(entry) {
        if (this.entries.has(entry.id)) {
            throw new Error(`approval: duplicate id ${entry.id}`);
        }
        this.entries.set(entry.id, { ...entry });
    }
    async get(id) {
        const e = this.entries.get(id);
        return e ? { ...e } : null;
    }
    async resolve(id, verdict) {
        const e = this.entries.get(id);
        if (!e || e.status !== "pending")
            return false;
        e.status = "resolved";
        e.verdict = verdict;
        return true;
    }
    async cancel(id) {
        const e = this.entries.get(id);
        if (!e || e.status !== "pending")
            return false;
        e.status = "cancelled";
        return true;
    }
    async expireOverdue(now = Date.now()) {
        let n = 0;
        for (const e of this.entries.values()) {
            if (e.status === "pending" && now > e.expiresAt) {
                e.status = "timedout";
                n += 1;
            }
        }
        return n;
    }
    /**
     * Enumerate all entries. Not part of the `ApprovalStore` contract — used
     * by dashboard routes to render the HITL queue and history.
     * Multi-instance prod deployments must replace this with a paginated
     * backing query (Redis ZRANGE, Postgres, ...).
     */
    async listAll() {
        return Array.from(this.entries.values(), (e) => ({ ...e }));
    }
}
//# sourceMappingURL=approval-channel.js.map