package config

import (
	"os"
)

type Config struct {
	Database DatabaseConfig
	JWT      JWTConfig
	Server   ServerConfig
	Groq     GroqConfig // NEW: Groq configuration
}

type ServerConfig struct {
	Port            string
	Environment     string
	UploadPath      string
	MaxUploadSize   int64
	AllowedOrigins  []string
}

// NEW: Groq configuration struct
type GroqConfig struct {
	APIKey          string
	DefaultModel    string
	MaxTokens       int
	Temperature     float64
	TopP            float64
}

func GetConfig() *Config {
	return &Config{
		Database: GetDatabaseConfig(),
		JWT:      GetJWTConfig(),
		Server:   GetServerConfig(),
		Groq:     GetGroqConfig(), // NEW
	}
}

func GetServerConfig() ServerConfig {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}

	env := os.Getenv("ENVIRONMENT")
	if env == "" {
		env = "development"
	}

	uploadPath := os.Getenv("UPLOAD_PATH")
	if uploadPath == "" {
		uploadPath = "./uploads"
	}

	return ServerConfig{
		Port:           port,
		Environment:    env,
		UploadPath:     uploadPath,
		MaxUploadSize:  10 * 1024 * 1024,
		AllowedOrigins: []string{"*"},
	}
}

// NEW: Get Groq configuration from environment
func GetGroqConfig() GroqConfig {
	apiKey := os.Getenv("GROQ_API_KEY")
	
	model := os.Getenv("GROQ_MODEL")
	if model == "" {
		model = "llama-3.3-70b-versatile" // Default to best model
	}

	return GroqConfig{
		APIKey:       apiKey,
		DefaultModel: model,
		MaxTokens:    1024,
		Temperature:  0.7,
		TopP:         0.95,
	}
}

func IsProduction() bool {
	return os.Getenv("ENVIRONMENT") == "production"
}

func IsDevelopment() bool {
	return os.Getenv("ENVIRONMENT") != "production"
}