import { randomUUID } from "node:crypto";
export class InMemorySecureStore {
    #secrets = new Map();
    async get(ref) {
        return this.#secrets.get(keyFor(ref))?.secret;
    }
    async set(ref, secret) {
        this.#secrets.set(keyFor(ref), {
            secret,
            updatedAt: new Date().toISOString(),
            credentialVersion: randomUUID(),
        });
    }
    async delete(ref) {
        this.#secrets.delete(keyFor(ref));
    }
    async status(ref) {
        const stored = this.#secrets.get(keyFor(ref));
        if (!stored)
            return { ref, state: "missing", backend: "in_memory" };
        return {
            ref,
            state: "available",
            maskedLabel: maskSecret(stored.secret),
            updatedAt: stored.updatedAt,
            credentialVersion: stored.credentialVersion,
            backend: "in_memory",
        };
    }
}
export function keyFor(ref) {
    return `${ref.provider}:${ref.kind}:${ref.accountId}`;
}
export function maskSecret(secret) {
    if (secret.length <= 8)
        return "••••";
    return `${secret.slice(0, 3)}•••${secret.slice(-4)}`;
}
