package auth

import (
	"context"
	"fmt"

	"sundynix-micro-go/app/auth/api/internal/svc"
	"sundynix-micro-go/app/auth/api/internal/types"
	"sundynix-micro-go/common/utils/captcha"

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

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

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

func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaResp, err error) {
	id, b64s, err := captcha.Generate()
	if err != nil {
		return nil, fmt.Errorf("生成验证码失败")
	}
	return &types.CaptchaResp{
		CaptchaId:  id,
		CaptchaImg: b64s,
	}, nil
}
