package middleware

import (
	"eslogad-be/internal/contract"
	"eslogad-be/internal/logger"

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

type UserIDResolver struct {
	userProcessor UserProcessor
	authProcessor AuthProcessor
}

func NewUserIDResolver(userProcessor UserProcessor, authProcessor AuthProcessor) *UserIDResolver {
	return &UserIDResolver{
		userProcessor: userProcessor,
		authProcessor: authProcessor,
	}
}

func (uir *UserIDResolver) Handle() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Next()
	}
}

func (uir *UserIDResolver) resolveUserID(c *gin.Context, userID uuid.UUID) (*contract.UserResponse, error) {
	user, err := uir.userProcessor.GetUserByID(c.Request.Context(), userID)
	if err != nil {
		logger.FromContext(c.Request.Context()).WithError(err).Error("UserIDResolver::resolveGopayUserID -> userID could not be resolved")
		return nil, err
	}
	return user, nil
}

func (uir *UserIDResolver) validate(c *gin.Context, tokenString string) string {
	return ""
}
