package mapping

import (
	"fmt"
	"log/slog"
	"strings"
)

func mappingLogger() *slog.Logger {
	return slog.Default()
}

func shortErr(err error) string {
	if err == nil {
		return ""
	}
	message := strings.TrimSpace(err.Error())
	limit := 180
	if strings.Contains(message, "empty openai-compatible response content (") {
		limit = 420
	}
	if len(message) > limit {
		return message[:limit] + "..."
	}
	return message
}

func generatorLabel(generator SuggestionGenerator) string {
	switch value := generator.(type) {
	case *ProviderAwareSuggestionGenerator:
		return "provider-aware"
	case *LLMSuggestionGenerator:
		source := strings.TrimSpace(value.source)
		if source == "" {
			return "llm"
		}
		return source
	case *RuleBasedSuggestionGenerator:
		return "rule-based"
	case *CompositeSuggestionGenerator:
		return "composite"
	default:
		return strings.TrimSpace(fmt.Sprintf("%T", generator))
	}
}
