package auth

import (
	"context"

	"apps/backend/internal/middleware"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *VerifyEmailLogic) VerifyEmail(req *types.AuthVerifyEmailReq) (resp *types.MemberPublic, err error) {
	uid, _ := middleware.UIDFrom(l.ctx)
	m, err := l.svcCtx.Auth.VerifyEmail(l.ctx, uid, req.Code)
	if err != nil {
		return nil, err
	}
	return types.MemberFromModel(m), nil
}
