package whatsapp

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

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

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

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

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

func (l *SetBusinessInfoLogic) SetBusinessInfo(req *types.SetBusinessReq) (*types.BaseMsgResp, error) {
	resp := types.BaseMsgResp{}

	websites := make([]*string, 0)
	for _, v := range req.Websites {
		if v == "" {
			continue
		}
		websites = append(websites, &v)
	}
	_, err := aliyun.SetCamsBusiness(*req.Phone, *req.WaId, req.Address, req.Description, req.Vertical, req.Email, req.ProfilePictureUrl, req.About, websites)

	if err != nil {
		resp.Msg = err.Error()
		resp.Code = 1
	}

	return &resp, nil
}
