package smtp

import "time"

const (
	DefaultMaxOutboxRetries = 8
	maxRetryDelay           = time.Hour
	baseRetryDelay          = 30 * time.Second
)

// OutboxRetryDelay returns exponential backoff before the next send attempt.
func OutboxRetryDelay(retryCount int) time.Duration {
	if retryCount <= 0 {
		return baseRetryDelay
	}
	delay := baseRetryDelay
	for i := 0; i < retryCount && delay < maxRetryDelay; i++ {
		if delay > maxRetryDelay/2 {
			delay = maxRetryDelay
			break
		}
		delay *= 2
	}
	if delay > maxRetryDelay {
		return maxRetryDelay
	}
	return delay
}
