package audit

import (
	"net/http"

	"nexavpn/backend/internal/apiutil"
)

type Handler struct {
	service *Service
}

func NewHandler(service *Service) *Handler {
	return &Handler{service: service}
}

func (h *Handler) List(w http.ResponseWriter, r *http.Request) {
	items, err := h.service.List(r.Context(), 100)
	if err != nil {
		apiutil.Error(w, http.StatusInternalServerError, "audit_list_failed", "unable to list audit logs")
		return
	}

	apiutil.JSON(w, http.StatusOK, items)
}
