package routes

import (
	"api/controllers"
	"os"

	"github.com/gofiber/fiber/v2"

	jwtware "github.com/gofiber/jwt/v3"
)

// Setup sets up the routes
func Setup(app *fiber.App) {

	app.Post("/integration", controllers.WixIntegration)

	app.Get("/version", controllers.Version)

	app.Post("/login", controllers.Login)
	app.Post("/register", controllers.AddUser)
	app.Get("/events", controllers.GetAllEvents)

	// Webhooks
	app.Post("/on_server_start", controllers.ServerStart)
	app.Post("/on_update", controllers.OnUpdate)
	app.Post("/on_pub_start", controllers.OnPubStart)
	app.Post("/on_pub_stop", controllers.OnPubStop)
	app.Post("/on_sub_start", controllers.OnSubStart)

	// Protected routes. Needs login before.
	protected := app.Group("/")
	protected.Use(jwtware.New(jwtware.Config{
		SigningKey: []byte(os.Getenv("API_SECRET")),
	}))

	protected.Get("servers", controllers.GetAllServers)
	protected.Post("server", controllers.AddServer)

	protected.Get("user", controllers.GetOwnUser)
	protected.Get("users", controllers.GetAllUsers)
	protected.Post("user", controllers.AddUser)

	protected.Post("event", controllers.AddEvent)
}
