package handlers

import (
	"net/http"
	"strconv"

	"github.com/acp/interceptor/internal/audit"
	"github.com/gin-gonic/gin"
)

// InsightsHandler serves governance visibility APIs for the dashboard.
type InsightsHandler struct {
	store audit.EventStore
}

// NewInsightsHandler constructs an insights handler.
func NewInsightsHandler(store audit.EventStore) *InsightsHandler {
	return &InsightsHandler{store: store}
}

// ListEvents returns recent governance events.
func (h *InsightsHandler) ListEvents(c *gin.Context) {
	limit := 50
	if v := c.Query("limit"); v != "" {
		if n, err := strconv.Atoi(v); err == nil && n > 0 {
			limit = n
		}
	}
	c.JSON(http.StatusOK, gin.H{
		"events": h.store.List(limit),
	})
}

// MetricsSummary returns aggregate decision metrics.
func (h *InsightsHandler) MetricsSummary(c *gin.Context) {
	c.JSON(http.StatusOK, h.store.Metrics())
}
