export function consumeRateLimit(buckets, key, maxAttempts, windowMs, blockMs, now = Date.now()) {
    const existing = buckets.get(key);
    if (existing?.blockedUntil && existing.blockedUntil > now) {
        return { limited: true, retryAfterMs: existing.blockedUntil - now };
    }
    if (!existing || existing.resetAt <= now) {
        buckets.set(key, { count: 1, resetAt: now + windowMs });
        return { limited: false };
    }
    existing.count += 1;
    if (existing.count > maxAttempts) {
        existing.blockedUntil = now + blockMs;
        return { limited: true, retryAfterMs: blockMs };
    }
    return { limited: false };
}
export function rateLimitStatus(buckets, key, now = Date.now()) {
    const existing = buckets.get(key);
    if (existing?.blockedUntil && existing.blockedUntil > now) {
        return { limited: true, retryAfterMs: existing.blockedUntil - now };
    }
    return { limited: false };
}
export function resetRateLimit(buckets, key) {
    buckets.delete(key);
}
