package fasthttpc

import (
	"github.com/valyala/fasthttp"
	"golang.org/x/time/rate"
	"time"
)

type (
	Config struct {
		timeout         time.Duration
		client          *fasthttp.Client
		noCheckStatus   bool
		qps             int
		qpsLimiter      *rate.Limiter
		maxConnPerHost  int
		fasthttpTimeout time.Duration
		useCtxTimeout   bool
	}

	ConfigOpt func(c *Config)
)

func WithTimout(v time.Duration) ConfigOpt {
	return func(c *Config) {
		c.timeout = v
	}
}

func WithUseCtxTimeout(v bool) ConfigOpt {
	return func(c *Config) {
		c.useCtxTimeout = v
	}
}

func WithFasthttpimout(v time.Duration) ConfigOpt {
	return func(c *Config) {
		c.fasthttpTimeout = v
	}
}

func WithClient(v *fasthttp.Client) ConfigOpt {
	return func(c *Config) {
		c.client = v
	}
}

func WithMaxConnPerHost(v int) ConfigOpt {
	return func(c *Config) {
		c.maxConnPerHost = v
	}
}

//func WithRedirectFn(v func(req *http.Request, via []*http.Request) error) ConfigOpt {
//	return func(c *Config) {
//		c.redirectFn = v
//	}
//}
//
//func WithNoRedirect() ConfigOpt {
//	return func(c *Config) {
//		c.redirectFn = func(req *http.Request, via []*http.Request) error {
//			return http.ErrUseLastResponse
//		}
//	}
//}

func WithNoCheckStatus(v bool) ConfigOpt {
	return func(c *Config) {
		c.noCheckStatus = v
	}
}

func WithQps(v int) ConfigOpt {
	return func(c *Config) {
		c.qps = v
	}
}

func WithQpsLimiter(v *rate.Limiter) ConfigOpt {
	return func(c *Config) {
		c.qpsLimiter = v
	}
}
