package tiktok_api

import (
	"fmt"
	"git.rosy.net.cn/jx-callback/globals"
	"strings"
	"testing"
)

func TestN2ame(t *testing.T) {
	polay := make(map[string]interface{}, 0)
	polay["a"] = ""
	polay["b"] = "1"

	fmt.Println(polay["a"].(string))
	fmt.Println(polay["b"].(string))
	fmt.Println(polay["c"].(string))
}

func TestGetRecommendCategory(t *testing.T) {
	img, _, err := GetTiktokImgListTest(a, "668707", "", "", "http://img20.360buyimg.com/vc/jfs/t1/8979/39/8591/236012/5c0e45f3E1537c120/a66aafc95cf66977.jpg", "http://img20.360buyimg.com/vc/jfs/t1/23027/3/955/82830/5c0e45f3E0855eeae/ae65ee9555a29579.jpg")
	fmt.Println(err)
	data, err := a.GetRecommendCategory(strings.Split(img, "|"))
	fmt.Println(data)
	fmt.Println(err)
}

// GetTiktokImgList 获取抖音图片链接
func GetTiktokImgListTest(api *API, storeId, appOrgCode string, detailImg string, img ...string) (string, string, error) {
	imgs := make([]Imgs, 0, 0)
	for _, v := range img {
		if v != "" {
			imgs = append(imgs, Imgs{
				Name: storeId + "_" + v[21:54],
				Url:  v,
			})
		}
	}
	if detailImg != "" {
		imgs = append(imgs, Imgs{
			Name: "detail_" + storeId + "_" + detailImg[21:54],
			Url:  detailImg,
		})
	}
	tiktokImgList, err := api.BatchUploadImages(imgs)
	if err != nil {
		return "", "", err
	}

	detailTiktok := ""
	var tiktokImg []string
	for k, v := range tiktokImgList {
		if strings.Contains(k, "detail_") {
			detailTiktok = v.ByteUrl
			continue
		}
		tiktokImg = append(tiktokImg, v.ByteUrl)
	}
	if detailTiktok == "" {
		detailTiktok = tiktokImg[0]
	}

	return strings.Join(tiktokImg, "|"), detailTiktok, nil
}

func TestGetSkuBrand(t *testing.T) {
	data, err := a.GetSkuBrand(23156, "娃哈哈")
	globals.SugarLogger.Debugf("data ========= %v", data)
	globals.SugarLogger.Debugf("data ========= %s", err)
}

func TestQualityList(t *testing.T) {
	a.QualityList(33079)
}
