package auth

import (
	"context"

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

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

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

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

func (l *ResetPasswordLogic) ResetPassword(req *types.AuthResetPasswordReq) (resp *types.OkData, err error) {
	code := req.Code
	if code == "" {
		code = req.Token
	}
	if err := l.svcCtx.Auth.ResetPassword(l.ctx, req.Email, code, req.NewPassword); err != nil {
		return nil, err
	}
	return &types.OkData{Ok: true, Message: "password updated"}, nil
}
