package server

import (
	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
	"skapp/pkg/config"
	"skapp/pkg/server/middleware"
	"skapp/pkg/server/router"
)

func Server(config *config.Config) (engine *gin.Engine) {
	if config.HasDebug() && config.Debug.Enable {
		gin.SetMode(gin.DebugMode)
		engine = gin.Default()
	} else {
		gin.SetMode(gin.ReleaseMode)
		engine = gin.New()
	}

	engine.Use(gzip.Gzip(gzip.DefaultCompression))
	engine.Use(middleware.CorsMiddleWare())
	engine.Use(middleware.ErrorHandler())

	g := engine.RouterGroup.Group("/s")
	router.SetupRouter(config, g)

	return engine
}
