package main

import (
	"log"
	"net/http"
	"os"

	"play-life-llm/internal/server"
)

func main() {
	ollamaHost := getEnv("OLLAMA_HOST", "http://localhost:11434")
	tavilyAPIKey := getEnv("TAVILY_API_KEY", "")
	port := getEnv("PORT", "8090")
	defaultModel := getEnv("OLLAMA_MODEL", "llama3.1:70b")

	cfg := server.Config{
		OllamaHost:   ollamaHost,
		TavilyAPIKey: tavilyAPIKey,
		DefaultModel: defaultModel,
	}
	router := server.NewRouter(cfg)

	addr := ":" + port
	log.Printf("play-life-llm listening on %s", addr)
	if err := http.ListenAndServe(addr, router); err != nil {
		log.Fatal(err)
	}
}

func getEnv(key, defaultVal string) string {
	if v := os.Getenv(key); v != "" {
		return v
	}
	return defaultVal
}
