import type { RateLimitManager } from './RateLimitManager' ; export class RateLimit < K > { /**
     * The remaining amount of times this entry can be dripped before the bucket is empty.
     */ public remaining ! : number ; /**
     * The timestamp that represents when this entry will reset back to a available state.
     */ public expires ! : number ; /**
     * The  RateLimitManager this entry is for.
      private manager : RateLimitManager < K > ; param manager public constructor ( manager ) { this . manager = manager ; this . reset ( ) ; } /**
     * Whether this entry is expired or not, allowing the bucket to be reset.
     */ public get expired ( ) : boolean { return this . remainingTime === 0 ; } /**
     * Whether this entry is limited or not.
     */ public get limited ( ) : boolean { return this . remaining === 0 && ! this . expired ; } /**
     * The remaining time in milliseconds before resetting.
     */ public get remainingTime ( ) : number { return Math . max ( this . expires - Date . now ( ) , 0 ) ; } /**
     * Consumes  RateLimit . remaining by one if it's not limited, calling  RateLimit . reset first if  RateLimit . expired is true.
      public consume ( ) { if ( this . limited ) throw new Error ( 'Cannot consume a limited bucket' ) ; if ( this . expired ) this . reset ( ) ; this . remaining -- ; return this ; } /**
     * Resets the entry back to it's full state.
     */ public reset ( ) { return this . resetRemaining ( ) . resetTime ( ) ; } /**
     * Resets the entry's  RateLimit . remaining uses back to full state.
      public resetRemaining ( ) { this . remaining = this . manager . limit ; return this ; } /**
     * Resets the entry's  RateLimit . expires to the current time plus  RateLimitManager . time .
      public resetTime ( ) { this . expires = Date . now ( ) + this . manager . time ; return this ; } }