package httpx

import (
	

	
)

// RetryCount enables retry for a request and sets the maximum retry count.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: retry count
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryCount(2))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryCount(2))
func ( int) OptionBuilder {
	return OptionBuilder{}.RetryCount()
}

func ( OptionBuilder) ( int) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryCount()
		},
		func( *req.Request) {
			.SetRetryCount()
		},
	))
}

// RetryFixedInterval sets a fixed retry interval for a request.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: retry interval
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryFixedInterval(200 * time.Millisecond))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryFixedInterval(200*time.Millisecond))
func ( time.Duration) OptionBuilder {
	return OptionBuilder{}.RetryFixedInterval()
}

func ( OptionBuilder) ( time.Duration) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryFixedInterval()
		},
		func( *req.Request) {
			.SetRetryFixedInterval()
		},
	))
}

// RetryBackoff sets a capped exponential backoff retry interval for a request.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: retry backoff
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryBackoff(100*time.Millisecond, 2*time.Second))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryBackoff(100*time.Millisecond, 2*time.Second))
func (,  time.Duration) OptionBuilder {
	return OptionBuilder{}.RetryBackoff(, )
}

func ( OptionBuilder) (,  time.Duration) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryBackoffInterval(, )
		},
		func( *req.Request) {
			.SetRetryBackoffInterval(, )
		},
	))
}

// RetryInterval sets a custom retry interval function for a request.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: custom retry interval
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryInterval(func(_ *req.Response, attempt int) time.Duration {
//		return time.Duration(attempt) * 100 * time.Millisecond
//	}))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryInterval(func(_ *req.Response, attempt int) time.Duration {
//		return time.Duration(attempt) * 100 * time.Millisecond
//	}))
func ( req.GetRetryIntervalFunc) OptionBuilder {
	return OptionBuilder{}.RetryInterval()
}

func ( OptionBuilder) ( req.GetRetryIntervalFunc) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryInterval()
		},
		func( *req.Request) {
			.SetRetryInterval()
		},
	))
}

// RetryCondition sets the retry condition for a request.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: retry on 503
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryCondition(func(resp *req.Response, _ error) bool {
//		return resp != nil && resp.StatusCode == 503
//	}))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryCondition(func(resp *req.Response, _ error) bool {
//		return resp != nil && resp.StatusCode == 503
//	}))
func ( req.RetryConditionFunc) OptionBuilder {
	return OptionBuilder{}.RetryCondition()
}

func ( OptionBuilder) ( req.RetryConditionFunc) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryCondition()
		},
		func( *req.Request) {
			.SetRetryCondition()
		},
	))
}

// RetryHook registers a retry hook for a request.
// @group Retry
//
// Applies to both client defaults and individual requests.
// Example: hook on retry
//
//	// Apply to all requests
//	c := httpx.New(httpx.RetryHook(func(_ *req.Response, _ error) {}))
//	httpx.Get[string](c, "https://example.com")
//
//	// Apply to a single request
//	httpx.Get[string](httpx.Default(), "https://example.com", httpx.RetryHook(func(_ *req.Response, _ error) {}))
func ( req.RetryHookFunc) OptionBuilder {
	return OptionBuilder{}.RetryHook()
}

func ( OptionBuilder) ( req.RetryHookFunc) OptionBuilder {
	return .add(bothOption(
		func( *Client) {
			.req.SetCommonRetryHook()
		},
		func( *req.Request) {
			.SetRetryHook()
		},
	))
}

// Retry applies a custom retry configuration to the client.
// @group Retry (Client)
//
// Applies only to client configuration.
// Example: configure client retry
//
//	c := httpx.New(httpx.Retry(func(rc *req.Client) {
//		rc.SetCommonRetryCount(2)
//	}))
//	_ = c
func ( func(*req.Client)) OptionBuilder {
	return OptionBuilder{}.Retry()
}

func ( OptionBuilder) ( func(*req.Client)) OptionBuilder {
	return .add(clientOnly(func( *Client) {
		if  == nil {
			return
		}
		(.req)
	}))
}