package http

import (
	"kpt-tmr-group/dep"
	"kpt-tmr-group/http/middleware"
	"kpt-tmr-group/http/route"

	"github.com/gin-gonic/gin"
)

type Server struct {
	*gin.Engine
}

type Option func(*Server)

func NewServer(options ...Option) *Server {
	s := &Server{
		Engine: gin.New(),
	}

	for _, option := range options {
		option(s)
	}

	return s
}

func ExportLogOption() Option {
	return func(s *Server) {
		s.Engine.Use(gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/metrics", "/check"}}))
	}
}

func SetRouteOption() Option {
	return func(s *Server) {
		route.HTTPServerRoute()(s.Engine)
	}
}

func WithDependency(dep *dep.HttpDependency) Option {
	return func(s *Server) {
		s.Engine.Use(middleware.WithDependency(dep))
	}
}