package routes

import (
	"github.com/aws/aws-sdk-go-v2/service/s3"
	"github.com/gin-contrib/logger"
	"github.com/gin-gonic/gin"
	"github.com/hongbo-miao/hongbomiao.com/api/api-go/internal/graphql_server/controllers"
	"github.com/hongbo-miao/hongbomiao.com/api/api-go/internal/graphql_server/handlers"
	sharedControllers "github.com/hongbo-miao/hongbomiao.com/api/api-go/internal/shared/controllers"
	sharedHandlers "github.com/hongbo-miao/hongbomiao.com/api/api-go/internal/shared/handlers"
	"github.com/valkey-io/valkey-go"
	"go.elastic.co/apm/module/apmgin/v2"
	"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
)

func SetupRouter(env string, valkeyClient valkey.Client, s3Client *s3.Client) *gin.Engine {
	r := gin.New()
	r.Use(apmgin.Middleware(r))
	if env == "development" {
		r.Use(handlers.CORSHandler())
	}
	r.Use(logger.SetLogger())
	r.Use(otelgin.Middleware("hm-graphql-server"))
	r.GET("/", sharedControllers.Health)
	r.GET("/metrics", sharedHandlers.PrometheusHandler())
	r.POST("/graphql", handlers.GraphQLHandler(valkeyClient))
	r.POST("/hasura/update-seed", controllers.UpdateSeed)
	r.POST("/hasura/role-event-trigger", controllers.RoleEventTrigger)
	r.POST("/predict", controllers.Predict)
	r.POST("/upload", controllers.Upload(s3Client))
	return r
}
