package api

import (
	"github.com/gin-gonic/gin"
	"github.com/olivere/elastic/v7"
	"gitlab.com/tensorsecurity-rd/waf-console/internal/controller"
	"gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
	"gorm.io/gorm"
)

func SetWafRouter(e *gin.Engine, clusterClientManager *utils.ClusterClientManager, db *gorm.DB, gatewayUrl string, elasticClient *elastic.Client) {
	v1 := e.Group("v1/api/waf")

	wafController := controller.NewWafController(clusterClientManager, db, gatewayUrl, elasticClient)
	v1.GET("", wafController.Waf)
	v1.POST("/", wafController.CreateWaf)
	v1.PUT("mode", wafController.UpdateMode)
	v1.PUT("rules", wafController.UpdateRule)
	v1.PUT("listener/enable", wafController.EnableListenerWaf)
	v1.PUT("gateway/enable", wafController.EnableGatewayWaf)
	v1.POST("listeners/enable", wafController.EnableListenerWafs)
	v1.DELETE("listener/:region_code/:namespace/:gateway_name/:port", wafController.DeleteListenerWaf)
	v1.DELETE("gateway/:region_code/:namespace/:gateway_name", wafController.DeleteGatewayWaf)
	v1.POST("debug/savecatagory", wafController.SaveRuleCategoryToDB)

	v2 := e.Group("api/v2/containerSec/waf")
	v2.GET("attack/log/list", wafController.ListAttackLogs)
	v2.GET("rules", wafController.ListRules)
	v2.PUT("rules", wafController.UpdateRule)
}
