package server

import (
	"github.com/gin-gonic/gin"
	"projectName/internal/handler"
	"projectName/internal/middleware"
	"projectName/pkg/helper/resp"
	"projectName/pkg/log"
)

func NewServerHTTP(
	logger *log.Logger,
	userHandler *handler.UserHandler,
	ipHandler *handler.IpHandler,
	ipAllowlist *middleware.IPAllowlist,
	ipRateLimiter *middleware.IPRateLimiter,
) *gin.Engine {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()
	r.Use(
		middleware.CORSMiddleware(),
		ipAllowlist.IPAllowlistMiddleware(),
		ipRateLimiter.RateLimitMiddleware(),
	)
	r.GET("/", func(ctx *gin.Context) {
		resp.HandleSuccess(ctx, map[string]interface{}{
			"say": "Hi Nunu!",
		})
	})

	r.GET("/user", userHandler.GetUserById)

	r.POST("/addIp", ipHandler.AddIp)
	r.POST("/deleteIp", ipHandler.DeleteIp)

	return r
}
