package tao_vegetable

import (
	"fmt"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475/request"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/globals"
)

// UploadImg 上传图片
func (a *API) UploadImg(param *request.AlibabaWdkPictureUploadRequest) (string, error) {
	client := ability1475.NewAbility1475(&a.client)

	data, err := client.AlibabaWdkPictureUpload(param, a.token)
	if err != nil {
		globals.SugarLogger.Debugf("requestId[%s],err[%s]", data.RequestId, utils.Format4Output(err, false))
		return "", err
	}

	if data.Result.ErrCode != nil {
		globals.SugarLogger.Debugf("requestId[%s],err[%s]", data.RequestId, utils.Format4Output(data.Result, false))
		return "", fmt.Errorf(*data.Result.ErrMsg)
	}

	return *data.Result.Model.FullUrl, nil
}
