package tao_vegetable

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability587/domain"
	"git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability587/request"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/globals"
	"go.uber.org/zap"
	"strings"
	"testing"
)

var (
	apiTao      *API
	sugarLogger *zap.SugaredLogger
)

/*{
"w2_valid": 1686799202942,
"r1_valid": 1702349402942,
"sp": "hema",
"r2_valid": 1687056602942,
"w1_valid": 1702349402942,
"locale": "zh_CN",
"user_id": "2215979737042",
"expire_time": 1702349402942,
"refresh_token": "50003C01414dSdI4diuByqeaiB124723d9yCmsxcIiMnXDrxjh0noxEuo20VpEXyHize",
"user_nick": "%E5%88%98%E7%A3%8A",
"refresh_token_valid_time": 1686797402942,
"access_token": "50002C00414zMSClqLiSDjBr2N19748391yiazjtFmsgTOdbBftik0XDfkUQywSmcjfC"
}
*/
func init() {
	apiTao = NewTaoVegetable(AppKey, AppSecret, ServerUrl)
	apiTao.SetToken("50002C00414zMSClqLiSDjBr2N19748391yiazjtFmsgTOdbBftik0XDfkUQywSmcjfC")
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)
}
func TestGetStoreCategory(t *testing.T) {
	data, err := apiTao.GetStoreCategoryInfo("")
	globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
	globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
}

func TestGetStoreAllCategory(t *testing.T) {
	data, err := apiTao.GetStoreAllCategory()
	globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
	globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
}

func TestAddCategory(t *testing.T) {
	data, err := apiTao.AddStoreCategoryInfo(&request.AlibabaWdkSkuCategoryAddRequest{Param: &domain.AlibabaWdkSkuCategoryAddCategoryDo{
		Code:      utils.String2Pointer("127382"),
		Name:      utils.String2Pointer("赠品专区"),
		Leaf:      utils.Bool2Point(false),
		Desc:      utils.String2Pointer("叶菜"),
		SortOrder: utils.Int64ToPointer(3),
	}})
	globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
	globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
}

func TestDeleteCategory(t *testing.T) {
	code := "2222"
	err := apiTao.DeleteStoreCategoryInfo(&request.AlibabaWdkSkuCategoryDeleteRequest{Param: &domain.AlibabaWdkSkuCategoryDeleteCategoryDo{Code: &code}})
	globals.SugarLogger.Debugf("err := %v", err)
}

func TestUpdateCategory(t *testing.T) {
	err := apiTao.UpdateStoreCategoryInfo(&request.AlibabaWdkSkuCategoryUpdateRequest{Param: &domain.AlibabaWdkSkuCategoryUpdateCategoryDo{
		Code:   utils.String2Pointer("127316"),
		Name:   utils.String2Pointer("时令鲜蔬"),
		Status: utils.Int64ToPointer(0),
	}})
	globals.SugarLogger.Debugf("err := %v", err)
}

func TestAbc(t *testing.T) {
	a := 1001
	c := float64(a) / float64(100)
	fmt.Println(c)
}

func TestShopUpdateInfo(t *testing.T) {
	start := "00:00"
	end := "24:00"
	err := apiTao.ShopUpdateInfo("JX668998", start, end)
	fmt.Println(err)
}

func TestShopUpdateRange(t *testing.T) {
	str := "116.508455,39.97171144419017;116.51455900796353,39.97130202157785;116.52047754873387,39.970086193839784;116.52603079044462,39.968100903286555;116.5310500006565,39.96540647196702;116.53538267320705,39.96208476881338;116.53889716203328,39.95823672209508;116.54148668117058,39.95397925276447;116.54307254939037,39.94944172187276;116.54360658088925,39.944762;116.54307254939037,39.940082278127235;116.54148668117058,39.935544747235525;116.53889716203328,39.931287277904914;116.53538267320705,39.92743923118662;116.5310500006565,39.92411752803297;116.52603079044462,39.92142309671344;116.52047754873387,39.91943780616021;116.51455900796353,39.918221978422146;116.508455,39.917812555809824;116.50235099203647,39.918221978422146;116.49643245126613,39.91943780616021;116.49087920955537,39.92142309671344;116.48585999934349,39.92411752803297;116.48152732679294,39.92743923118662;116.47801283796672,39.931287277904914;116.47542331882941,39.935544747235525;116.47383745060962,39.940082278127235;116.47330341911075,39.944762;116.47383745060962,39.94944172187276;116.47542331882941,39.95397925276447;116.47801283796672,39.95823672209508;116.48152732679294,39.96208476881338;116.48585999934349,39.96540647196702;116.49087920955537,39.968100903286555;116.49643245126613,39.970086193839784;116.50235099203647,39.97130202157785"
	temp := strings.Split(str, ";")
	points := make([]Points, 0)
	for _, v := range temp {
		s := strings.Split(v, ",")
		point := Points{
			Lng: s[0],
			Lat: s[1],
		}
		points = append(points, point)
	}
	err := apiTao.ShopUpdateRange("JX668998", points)
	fmt.Println(err)
}
