package codex

// Close stops background token refresh for the provider and all nested backends.
func (c *Codex) Close() error {
	if c == nil {
		return nil
	}
	if c.modelCache != nil {
		_ = c.modelCache.Close()
	}
	if c.tokenManager != nil {
		c.tokenManager.Stop()
	}
	for _, backend := range c.authBackends {
		_ = backend.Close()
	}
	for _, fallback := range c.fallbacks {
		_ = fallback.Close()
	}
	return nil
}
