package rest

import (
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"

	_ "quantex.com/qfixdpl/src/client/api/rest/docs" // Swag needs this import to work properly
)

func SetRoutes(api *API) {
	cont := api.Controller

	v1 := api.Router.Group("/qfixdpl/v1")
	api.Router.Use(cont.Options)
	{
		auth := v1.Group("/auth")
		auth.POST("/login", cont.Login)
	}

	qfixdpl := v1.Group("/")
	qfixdpl.Use(cont.AuthRequired)
	qfixdpl.GET("/health", cont.HealthCheck)
	qfixdpl.GET("/trades", cont.GetTrades)
	qfixdpl.GET("/trades/:quoteReqID/logs", cont.GetLogs)
	qfixdpl.GET("/quote-requests", cont.GetPendingQuoteRequests)

	// services group: API-key auth via body, no session cookie required.
	services := v1.Group("/")
	services.POST("/messages", cont.AllMessages)
	services.POST("/quotes", cont.SendQuote)
	services.POST("/quotes/cancel", cont.CancelQuote)

	backoffice := qfixdpl.Group("/backoffice")
	backoffice.Use(cont.BackOfficeUser)

	admin := qfixdpl.Group("/admin")
	admin.Use(cont.SuperUser)

	SetSwagger(v1, cont)
}

func SetSwagger(path *gin.RouterGroup, cont *Controller) {
	auth := path.Group("/")
	auth.Use(cont.AuthRequired)

	auth.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
