package handler

import (
	"kra/internal/modules/system/service"
	"kra/internal/modules/system/transport/httpx"

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

type Session struct{ tokens *service.TokenService }

func NewSession(tokens *service.TokenService) *Session { return &Session{tokens: tokens} }
func (h *Session) Logout(c *gin.Context) {
	token := c.GetHeader("x-token")
	if token == "" {
		token, _ = c.Cookie("x-token")
	}
	if err := h.tokens.BlacklistToken(c.Request.Context(), token); err != nil {
		httpx.Fail(c, "jwt作废失败")
		return
	}
	httpx.SetTokenCookie(c, "", -1)
	httpx.Write(c, httpx.CodeSuccess, gin.H{}, "jwt作废成功")
}
