package clientip

import (
	"go.uber.org/zap"

	"codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/config"
)

// ProvideExtractor provides a client IP extractor configured from the application config
func ProvideExtractor(cfg *config.Config, logger *zap.Logger) (*Extractor, error) {
	// If no trusted proxies configured, use default (no X-Forwarded-For trust)
	if len(cfg.Security.TrustedProxies) == 0 {
		logger.Info("no trusted proxies configured - X-Forwarded-For headers will be ignored for security")
		return NewDefaultExtractor(logger), nil
	}

	// Create extractor with trusted proxies
	return NewExtractor(cfg.Security.TrustedProxies, logger)
}
