// Code scaffolded by goctl. Safe to edit.
package member

import (
	"context"

	"gateway/internal/svc"
	"gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type VerifyTOTPLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewVerifyTOTPLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifyTOTPLogic {
	return &VerifyTOTPLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *VerifyTOTPLogic) VerifyTOTP(req *types.TOTPVerifyReq) error {
	actor, err := actorOrErr(l.ctx)
	if err != nil {
		return err
	}
	if err := requireTOTP(l.svcCtx); err != nil {
		return err
	}
	code := ""
	if req != nil {
		code = req.Code
	}
	return l.svcCtx.MemberTOTP.VerifyCode(l.ctx, actor.TenantID, actor.UID, code)
}
