package routing

import "github.com/gin-gonic/gin"

type Handlers struct {
	Health             gin.HandlerFunc
	Index              gin.HandlerFunc
	ShowBox            gin.HandlerFunc
	BoxLogin           gin.HandlerFunc
	BoxLoginPost       gin.HandlerFunc
	BoxStatus          gin.HandlerFunc
	DownloadBox        gin.HandlerFunc
	DownloadFile       gin.HandlerFunc
	DownloadThumbnail  gin.HandlerFunc
	CreateBox          gin.HandlerFunc
	ManifestFileUpload gin.HandlerFunc
	FileStatusUpdate   gin.HandlerFunc
	DirectBoxUpload    gin.HandlerFunc
	LegacyUpload       gin.HandlerFunc

	AdminLogin          gin.HandlerFunc
	AdminLoginPost      gin.HandlerFunc
	AdminLogout         gin.HandlerFunc
	AdminDashboard      gin.HandlerFunc
	AdminAlerts         gin.HandlerFunc
	AdminBoxes          gin.HandlerFunc
	AdminBoxesAction    gin.HandlerFunc
	AdminUsers          gin.HandlerFunc
	AdminActivity       gin.HandlerFunc
	AdminSecurity       gin.HandlerFunc
	AdminAlertsAction   gin.HandlerFunc
	AdminSecurityAction gin.HandlerFunc
	AdminSettings       gin.HandlerFunc
	AdminSettingsExport gin.HandlerFunc
	AdminSettingsSave   gin.HandlerFunc
	AdminSettingsImport gin.HandlerFunc
	AdminSettingsReset  gin.HandlerFunc
	AdminAuth           gin.HandlerFunc
}

func Register(router *gin.Engine, handlers Handlers) {
	router.GET("/health", handlers.Health)
	router.GET("/", handlers.Index)

	router.GET("/box/:id", handlers.ShowBox)
	router.GET("/box/:id/login", handlers.BoxLogin)
	router.GET("/box/:id/status", handlers.BoxStatus)
	router.GET("/box/:id/download", handlers.DownloadBox)
	router.GET("/box/:id/files/:filename", handlers.DownloadFile)
	router.GET("/box/:id/thumbnails/:file_id", handlers.DownloadThumbnail)

	router.POST("/box", handlers.CreateBox)
	router.POST("/box/:id/login", handlers.BoxLoginPost)
	router.POST("/box/:id/files/:file_id/upload", handlers.ManifestFileUpload)
	router.POST("/box/:id/files/:file_id/status", handlers.FileStatusUpdate)

	// Legacy upload routes are kept for compatibility with older clients.
	router.POST("/box/:id/upload", handlers.DirectBoxUpload)
	router.POST("/upload", handlers.LegacyUpload)

	admin := router.Group("/admin")
	admin.GET("/login", handlers.AdminLogin)
	admin.POST("/login", handlers.AdminLoginPost)
	admin.GET("/logout", handlers.AdminLogout)

	protected := router.Group("/admin", handlers.AdminAuth)
	protected.GET("/dashboard", handlers.AdminDashboard)
	protected.GET("/alerts", handlers.AdminAlerts)
	protected.POST("/alerts/actions", handlers.AdminAlertsAction)
	protected.GET("/boxes", handlers.AdminBoxes)
	protected.POST("/boxes/actions", handlers.AdminBoxesAction)
	protected.GET("/users", handlers.AdminUsers)
	protected.GET("/activity", handlers.AdminActivity)
	protected.GET("/security", handlers.AdminSecurity)
	protected.POST("/security/actions", handlers.AdminSecurityAction)
	protected.GET("/settings", handlers.AdminSettings)
	protected.GET("/settings/export", handlers.AdminSettingsExport)
	protected.POST("/settings/save", handlers.AdminSettingsSave)
	protected.POST("/settings/import", handlers.AdminSettingsImport)
	protected.POST("/settings/reset", handlers.AdminSettingsReset)
}
