package whatsapp

import (
	"context"
	"wechat-api/hook/aliyun"

	"wechat-api/internal/svc"
	"wechat-api/internal/types"

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

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

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

func (l *SendWhatsappCodeLogic) SendWhatsappCode(req *types.SendCodeReq) (*types.BaseMsgResp, error) {
	resp := types.BaseMsgResp{}
	_, err := aliyun.SendCamsCode(*req.Cc+*req.Phone, *req.WaId, *req.Method, *req.Locale)
	l.Logger.Infof("err=%v\n", err)

	if err != nil {
		resp.Msg = err.Error()
		resp.Code = 1
	} else {
		resp.Msg = "发送成功"
	}

	return &resp, nil
}
