package fees

import (
	"strings"

	internalcalculator "github.com/tech/sendico/billing/fees/internal/service/fees/internal/calculator"
	oracleclient "github.com/tech/sendico/fx/oracle/client"
	clockpkg "github.com/tech/sendico/pkg/clock"
)

// Option configures a Service instance.
type Option func(*Service)

// WithClock sets a custom clock implementation.
func WithClock(clock clockpkg.Clock) Option {
	return func(s *Service) {
		if clock != nil {
			s.clock = clock
		}
	}
}

// WithCalculator sets a custom calculator implementation.
func WithCalculator(calculator Calculator) Option {
	return func(s *Service) {
		if calculator != nil {
			s.calculator = calculator
		}
	}
}

// WithOracleClient wires an FX oracle client for FX trigger evaluations.
func WithOracleClient(oracle oracleclient.Client) Option {
	return func(s *Service) {
		s.oracle = oracle
		// Rebuild default calculator if none was injected.
		if s.calculator == nil {
			s.calculator = internalcalculator.New(s.logger, oracle)
		}
	}
}

// WithFeeResolver injects a custom fee resolver (useful for tests).
func WithFeeResolver(r FeeResolver) Option {
	return func(s *Service) {
		if r != nil {
			s.resolver = r
		}
	}
}

// WithDiscoveryInvokeURI sets the invoke URI used when announcing the service in discovery.
func WithDiscoveryInvokeURI(invokeURI string) Option {
	return func(s *Service) {
		s.invokeURI = strings.TrimSpace(invokeURI)
	}
}
