package middleware

import (
	"net/http"

	"haixun-backend/internal/config"
	authusecase "haixun-backend/internal/model/auth/domain/usecase"
)

// AuthJWTMiddleware enforces Bearer member JWT on protected routes.
// Mounted via @server(middleware: AuthJWT) in generate/api/*.api.
type AuthJWTMiddleware struct {
	tokens authusecase.TokenUseCase
	cfg    config.AuthConf
}

func NewAuthJWTMiddleware(tokens authusecase.TokenUseCase, cfg config.AuthConf) *AuthJWTMiddleware {
	return &AuthJWTMiddleware{tokens: tokens, cfg: cfg}
}

func (m *AuthJWTMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return Auth(m.tokens, m.cfg, next)
}
