package rest

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

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

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

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

	qfixpt := v1.Group("/")
	qfixpt.Use(cont.AuthRequired)
	qfixpt.GET("/health", cont.HealthCheck)
	qfixpt.GET("/trade_capture_reports", cont.TradeCaptureReports)
	qfixpt.GET("/trades/all", cont.GetAllTrades)
	qfixpt.GET("/trades/:tradeID/logs", cont.GetTradeLogs)

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

	admin := qfixpt.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))
}
