export class RateLimiter {
  private lastRequest: number = 0;
  private minDelay: number;
  
  constructor(minDelayMs: number = 1000) {
    this.minDelay = minDelayMs;
  }
  
  async throttle(): Promise<void> {
    const now = Date.now();
    const timeSinceLastRequest = now - this.lastRequest;
    
    if (timeSinceLastRequest < this.minDelay) {
      await this.delay(this.minDelay - timeSinceLastRequest);
    }
    
    this.lastRequest = Date.now();
  }
  
  private delay(ms: number): Promise<void> {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
}