package api

import (
	"net/http"

	"github.com/gin-gonic/gin"

	"github.com/rycroftapparel/workpulse-api/internal/httpapi"
)

// adminBackfillReportCalendar re-syncs calendar_events from all reports with report_date (superadmin).
func (s *Server) adminBackfillReportCalendar(c *gin.Context) {
	ctx, cancel := s.ctx(c)
	defer cancel()
	n, err := s.BackfillReportCalendarEvents(ctx)
	if err != nil {
		c.JSON(http.StatusInternalServerError, httpapi.Fail("db", err.Error()))
		return
	}
	c.JSON(http.StatusOK, httpapi.OK(gin.H{
		"syncedReports": n,
		"message":       "Calendar events refreshed from daily reports",
	}))
}
