package router

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

	// JWT middleware
	jwtMiddleware := createJWTMiddleware(cfg)

	// Protected routes
	protected := e.Group("/api", jwtMiddleware)
	devices := protected.Group("/devices")

	// Public device registration routes (no auth required)
	e.POST("/api/devices/register", cfg.DeviceHandler.InitiateRegistration)
	e.POST("/api/devices/register/status", cfg.DeviceHandler.CheckRegistrationStatus)

	// Device management routes (protected)
	devices.GET("", cfg.DeviceHandler.ListDevices)
	devices.GET("/:id", cfg.DeviceHandler.GetDevice)
	devices.PUT("/:id", cfg.DeviceHandler.UpdateDevice)
	devices.DELETE("/:id", cfg.DeviceHandler.DeleteDevice)

	// Token regeneration endpoint (JWT authentication required)
	devices.PUT("/:id/regenerate-token", cfg.DeviceHandler.RegenerateDeviceToken)

	devices.GET("/pending", cfg.DeviceHandler.ListPendingRegistrations)
	devices.GET("/approve/:registration_id", cfg.DeviceHandler.ApproveDevice)
	devices.POST("/reject/:registration_id", cfg.DeviceHandler.RejectDevice)

	// Device sidecar configuration routes
	devices.GET("/:id/sidecar", cfg.SidecarHandler.GetSidecarConfig)
	devices.GET("/:id/sidecar/download", cfg.SidecarHandler.DownloadSidecarConfig)
}
