package handlers

import (
	"net/http"

	"github.com/breakpilot/ai-compliance-sdk/internal/iace"
	"github.com/gin-gonic/gin"
)

// ListOperationalStates handles GET /operational-states
// Returns the 9 machine operational states with DE/EN labels and
// the 20 standard state transitions (directed edges of the state graph).
func (h *IACEHandler) ListOperationalStates(c *gin.Context) {
	type stateInfo struct {
		ID      string `json:"id"`
		LabelDE string `json:"label_de"`
		LabelEN string `json:"label_en"`
		Sort    int    `json:"sort_order"`
	}

	labels := []stateInfo{
		{ID: "startup", LabelDE: "Hochfahren", LabelEN: "Startup", Sort: 1},
		{ID: "homing", LabelDE: "Referenzfahrt", LabelEN: "Homing", Sort: 2},
		{ID: "automatic_operation", LabelDE: "Automatikbetrieb", LabelEN: "Automatic Operation", Sort: 3},
		{ID: "manual_operation", LabelDE: "Handbetrieb", LabelEN: "Manual Operation", Sort: 4},
		{ID: "teach_mode", LabelDE: "Einrichtbetrieb", LabelEN: "Teach Mode", Sort: 5},
		{ID: "maintenance", LabelDE: "Wartung", LabelEN: "Maintenance", Sort: 6},
		{ID: "cleaning", LabelDE: "Reinigung", LabelEN: "Cleaning", Sort: 7},
		{ID: "emergency_stop", LabelDE: "Not-Halt", LabelEN: "Emergency Stop", Sort: 8},
		{ID: "recovery_mode", LabelDE: "Wiederanlauf", LabelEN: "Recovery Mode", Sort: 9},
	}

	transitions := iace.StandardStateTransitions()

	c.JSON(http.StatusOK, gin.H{
		"operational_states": labels,
		"transitions":       transitions,
		"total_states":      len(labels),
		"total_transitions": len(transitions),
	})
}
