package handlers

import (
	"net/http"
)

// GET /api/tools/fristenrechner/event-categories — returns the full
// decision-tree taxonomy for the v3 Pathway B / B1 cascade UI
// (t-paliad-133). Tree is small (~100 nodes) and mostly static; the
// frontend ETag-caches it via localStorage.
//
// Returns 503 if the DB-backed services aren't wired (DATABASE_URL
// unset).
func handleFristenrechnerEventCategories(w http.ResponseWriter, r *http.Request) {
	if dbSvc == nil || dbSvc.eventCategory == nil {
		writeJSON(w, http.StatusServiceUnavailable, map[string]string{
			"error": "Decision-tree-Taxonomie vorübergehend nicht verfügbar (keine Datenbank).",
		})
		return
	}
	tree, err := dbSvc.eventCategory.Tree(r.Context())
	if err != nil {
		writeJSON(w, http.StatusInternalServerError, map[string]string{
			"error": "Decision-tree fehlgeschlagen: " + err.Error(),
		})
		return
	}
	writeJSON(w, http.StatusOK, map[string]any{
		"tree": tree,
	})
}
