package ratelimit

//  Fork github.com/ulule/limiter

import (
	"context"
	"time"
)

const (
	// DefaultPrefix is the default prefix to use for the key in the store.
	DefaultPrefix = "limiter"

	// DefaultCleanUpInterval is the default time duration for cleanup.
	DefaultCleanUpInterval = 30 * time.Second
)

// Context is the limit context.
type Context struct {
	Limit     int64
	Remaining int64
	Reset     int64
	Reached   bool
}

// Limiter is the limiter instance.
type Limiter struct {
	Store   Store
	Rate    Rate
	Key     string
	Methods []Method
}

type Method struct {
	Name string
}

// New returns an instance of Limiter.
func New(store Store, rate Rate, key string, methods []Method) *Limiter {
	return &Limiter{
		Store:   store,
		Rate:    rate,
		Key:     key,
		Methods: methods,
	}
}

// Get returns the limit for given identifier.
func (limiter *Limiter) Get(ctx context.Context, key string) (Context, error) {
	return limiter.Store.Get(ctx, key, limiter.Rate)
}

// Peek returns the limit for given identifier, without modification on current values.
func (limiter *Limiter) Peek(ctx context.Context, key string) (Context, error) {
	return limiter.Store.Peek(ctx, key, limiter.Rate)
}

// Reset sets the limit for given identifier to zero.
func (limiter *Limiter) Reset(ctx context.Context, key string) (Context, error) {
	return limiter.Store.Reset(ctx, key, limiter.Rate)
}
