package router

func registerCollectionsRoutes(cfg *Config) {
	e := cfg.Echo

	// JWT middleware for protected routes
	jwtMiddleware := createJWTMiddleware(cfg)
	protected := e.Group("/api", jwtMiddleware)

	// Collections API routes
	collections := protected.Group("/collections")
	collections.GET("", cfg.CollectionHandler.GetCollections)
	collections.POST("", cfg.CollectionHandler.CreateCollection)
	collections.GET("/:id", cfg.CollectionHandler.GetCollection)
	collections.PUT("/:id", cfg.CollectionHandler.UpdateCollection)
	collections.DELETE("/:id", cfg.CollectionHandler.DeleteCollection)
	collections.GET("/:id/books", cfg.CollectionHandler.GetBookCollections)
	collections.POST("/:id/books", cfg.CollectionHandler.AddBooks)
	collections.DELETE("/:id/books/:bookId", cfg.CollectionHandler.RemoveBook)
	collections.POST("/:id/books/bulk-remove", cfg.CollectionHandler.BulkRemoveBooks)
	collections.POST("/bulk-add-books", cfg.CollectionHandler.HandleBulkAddBooks)
	collections.POST("/test-rules", cfg.CollectionHandler.TestRules)
	collections.POST("/preview", cfg.CollectionHandler.PreviewCollection)

	// Device shelf mapping routes
	deviceCollections := protected.Group("/devices/:id/collections")
	deviceCollections.GET("", cfg.CollectionHandler.GetDeviceMappings)
	deviceCollections.POST("", cfg.CollectionHandler.CreateDeviceMapping)
	deviceCollections.PUT("/:collectionId", cfg.CollectionHandler.UpdateDeviceMapping)
	deviceCollections.DELETE("/:collectionId", cfg.CollectionHandler.DeleteDeviceMapping)
}
