package handlers

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"armature/store"
)

// ClusterHandler serves the admin cluster API.
type ClusterHandler struct {
	stores store.Stores
}

func NewClusterHandler(stores store.Stores) *ClusterHandler {
	return &ClusterHandler{stores: stores}
}

// ListNodes returns all registered cluster nodes.
// GET /api/v1/admin/cluster
func (h *ClusterHandler) ListNodes(c *gin.Context) {
	nodes, err := h.stores.Cluster.ListNodes(c.Request.Context())
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list cluster nodes"})
		return
	}
	if nodes == nil {
		nodes = []store.ClusterNode{}
	}
	c.JSON(http.StatusOK, gin.H{"data": nodes})
}
