package captcha

import (
	"context"

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type ValidateCaptchaLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewValidateCaptchaLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *ValidateCaptchaLogic {
	return &ValidateCaptchaLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ValidateCaptchaLogic) ValidateCaptcha(req *types.ValidateCaptchaReq) error {
	if err := l.svcCtx.Captcha.Verify(req.CaptchaId, req.Captcha, req.Clear); err != nil {
		return err
	}
	return nil
}
