package routes

import (
	"fotbal-club/internal/controllers"
	"fotbal-club/internal/middleware"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

func RegisterAnalyticsRoutes(router *gin.RouterGroup, db *gorm.DB) {
	analyticsController := controllers.NewAnalyticsController(db)
	
	// Public tracking endpoint (no auth, rate-limited)
	router.POST("/analytics/track", middleware.RateLimit(120, time.Minute), analyticsController.TrackEvent)
	
	// Analytics visitors endpoint (protected, used by dashboard widgets)
	router.GET("/analytics/visitors", middleware.JWTAuth(db), middleware.RoleAuth("admin"), analyticsController.GetVisitors)
	
	// Protected admin routes
	admin := router.Group("/admin/analytics")
	admin.Use(middleware.JWTAuth(db))
	admin.Use(middleware.RoleAuth("admin"))
	{
		admin.GET("", analyticsController.GetAnalytics) // GET /admin/analytics (summary)
		admin.GET("/overview", analyticsController.GetAnalyticsOverview)
		admin.GET("/top-pages", analyticsController.GetTopPages)
		admin.GET("/top-articles", analyticsController.GetTopArticles)
		admin.GET("/top-interactions", analyticsController.GetTopInteractions)
	}
}
