package auth

import (
	"net/http"
	"time"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type Handler struct {
	log *zap.SugaredLogger
}

func NewHandler(log *zap.SugaredLogger) *Handler {
	return &Handler{
		log: log,
	}
}

func (h *Handler) RegisterRoutes(rg *gin.RouterGroup) {
	rg.POST("/login", h.Login)
}

func setRefreshTokenCookie(c *gin.Context, token string) {
	maxAge := time.Hour * 24 * 7
	c.SetCookie(
		"refresh_token", // name
		token,           // value
		int(maxAge),     // maxAge (seconds, 7 days)
		"/",             // path
		"",              // domain
		false,           // secure (true in production)
		true,            // httpOnly
	)
}

func (h *Handler) Login(c *gin.Context) {
	// var req users.LoginReq
	// if err := c.ShouldBindJSON(&req); err != nil {
	// 	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	// 	return
	// }
	//
	// res := h.service.Login(req)
	// setRefreshTokenCookie(c, res.RefreshToken)
	c.JSON(http.StatusOK, gin.H{"msg": "ok"})
}
