"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

Sliding-window rate limiter: at most `limit` calls per `window_s` —
REQ-2.3.3.
"""

from __future__ import annotations

import time
from collections import deque

from .errors import RateLimitExceededError


class RateLimiter:
    def __init__(self, limit: int = 100, window_s: float = 1.0) -> None:
        self._limit = limit
        self._window_s = window_s
        self._timestamps: deque[float] = deque()

    def acquire(self) -> None:
        now = time.monotonic()
        while self._timestamps and now - self._timestamps[0] >= self._window_s:
            self._timestamps.popleft()

        if len(self._timestamps) >= self._limit:
            raise RateLimitExceededError()
        self._timestamps.append(now)
