// 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 GetTOTPStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *GetTOTPStatusLogic) GetTOTPStatus() (*types.TOTPStatusData, error) {
	actor, err := actorOrErr(l.ctx)
	if err != nil {
		return nil, err
	}
	if err := requireTOTP(l.svcCtx); err != nil {
		return nil, err
	}
	status, err := l.svcCtx.MemberTOTP.Status(l.ctx, actor.TenantID, actor.UID)
	if err != nil {
		return nil, err
	}
	cfg := l.svcCtx.Config.Member.Defaults().TOTP
	return &types.TOTPStatusData{
		Enrolled:             status.Enrolled,
		EnrolledAt:           status.EnrolledAt,
		BackupCodesRemaining: status.BackupCodesRemaining,
		Digits:               cfg.Digits,
		PeriodSeconds:        cfg.PeriodSeconds,
	}, nil
}
