package server

import (
	"github.com/labstack/echo/v4"
)

// setupRoutes configures all API routes using nested routers
func setupRoutes(s *Server, e *echo.Echo) {
	// API v1 group
	api := e.Group("/api/v1")

	setupRadiosRoutes(s, api.Group("/radios"))
	setupMeshCoreRoutes(s, api.Group("/meshcore"))
	setupAPRSRoutes(s, api.Group("/aprs"))
}

// setupRadiosRoutes configures routes for radio endpoints
func setupRadiosRoutes(s *Server, root *echo.Group) {
	root.GET("", s.handleGetRadios)
	root.GET("/:protocol", s.handleGetRadios)
}

// setupMeshCoreRoutes configures routes for MeshCore endpoints
func setupMeshCoreRoutes(s *Server, root *echo.Group) {
	// Stats endpoint
	root.GET("", s.handleGetMeshCore)

	// Groups endpoints
	root.GET("/groups", s.handleGetMeshCoreGroups)

	// Nodes endpoints
	nodes := root.Group("/nodes")
	nodes.GET("", s.handleGetMeshCoreNodes)
	nodes.GET("/close-to/:publickey", s.handleGetMeshCoreNodesCloseTo)

	// Packets endpoint
	root.GET("/packets", s.handleGetMeshCorePackets)

	// Commented out routes from original
	// meshcore.GET("/path/:origin/:path", s.handleGetMeshCorePath)
	// meshcore.GET("/sources", s.handleGetMeshCoreSources)
}

// setupAPRSRoutes configures routes for APRS endpoints
func setupAPRSRoutes(s *Server, root *echo.Group) {
	// Packets endpoint
	root.GET("/packets", s.handleGetAPRSPackets)
}
