package middleware

import (
	"net/http"

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

// MemberAuthMiddleware enforces member JWT from X-Member-Authorization.
// AI routes keep Authorization for provider API keys.
// Mounted via @server(middleware: MemberAuth) in generate/api/ai.api.
type MemberAuthMiddleware struct {
	tokens authusecase.TokenUseCase
	cfg    config.AuthConf
}

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

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