package gome_live_show

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
	"testing"
)

var (
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)
}

func TestGuoMei(t *testing.T) {
	appKey := "N0R033L2QQFR53"
	secretKey := "686ffc3e31c24594838baed045563790"

	api := New(appKey, secretKey, "")
	data, err := api.GetAccessToken()
	fmt.Println(err)
	fmt.Println(data)

}

// 查询门店列表
func TestStoreList(t *testing.T) {
	data, _ := api.QueryStoreList(&GetStoreListReq{
		StoreName: "京西",
	})

	for _, v := range data.Data.Records {
		fmt.Println(v.StoreName)
		fmt.Println(v.StoreCode)
	}
}

// 查询门店分类
func TestQueryCategory(t *testing.T) {
	data, _ := api.QueryStoreCategoryList(&QueryStoreGoodsCategoryListReq{
		Page: Page{
			PageSize:   50,
			PageNumber: 1,
		},
		StoreCode: "GMJ-MS-XOMRF-1J1",
	})

	for _, v := range data.Data.Records {
		fmt.Println(v.CategoryCode)
		fmt.Println(v.CategoryName)
		fmt.Println(v.Rank)
	}
}

// 图片上传
func TestUploadImg(t *testing.T) {
	data := `data:image/png;base64,[encoded data, 97220 characters]`
	//dataByte := []byte(data)
	data1, err := api.UploadPicture(data, 1, "aaaa.png")
	fmt.Println(data1)
	fmt.Println(err)
}

// 添加门店分类
func TestNew(t *testing.T) {
	data, err := api.AddStoreCategory(&StoreAddGoodsCategory{
		StoreCode:    "GMJ-MS-XOMRF-1J1",
		CategoryName: "新鲜海鲜",
		Rank:         3,
	})
	fmt.Println("err===", err)
	fmt.Println("err===", data.Code)
}

// 新增商户商品
func TestAddGoods1(t *testing.T) {
	api.CreateMerchantGoodsOnStore(&CreateGoodsListToStore{
		GoodsName:      "小包菜",
		MainPictureURL: "xxxxx.jpg",
		Detail:         "多汁的小包菜",
		Cat3Code:       "",
		SpecProperty:   nil,
		SkuSaleList:    nil,
		GoodsType:      "",
		//OtherPictureURL: nil,
		//VideoURL:        "",
		//SpecCode:        "",
		//SpecName:        "",
		//SpecValues:      "",
		//SpecValueCode:   "",
		//SpecValueName:   "",
		//Specification:   "",
		//MarketPrice:     0,
		//ThirdSkuCode:    "",
	})
}

// 查询商户商品列表
func TestQueryMerchGoodsList(t *testing.T) {
	data, err := api.GetMerchantStoreGoodsList(&QueryStoreGoodsListReq{
		GoodsName: "",
		Cat3Code:  "",
		Page:      Page{},
	})
	fmt.Println("err===", err)
	fmt.Println("err===", data)
}

// 查询所有的品类
func TestGetAllCategoryList(t *testing.T) {
	data, _ := api.GetGoodsCategoryList()
	t.Log(data.Data)
	for _, v := range data.Data {
		fmt.Println(v.CatCode)
		fmt.Println(v.CatLevel)
		fmt.Println(v.CatName)
		if len(v.ChildCat) > 0 {
			for _, d := range v.ChildCat {
				fmt.Println(d.CatCode)
				fmt.Println(d.CatLevel)
				fmt.Println(d.CatName)
			}
		}
	}
}

// 商户商品创建
func TestGoMeiMerStoreAddGoods(t *testing.T) {
	// 获取商品三级目录
	data, _ := api.QueryGoodsSizeList(&QueryGoodsSpecSizeReq{
		Cat3Code: "",
		SpecName: "",
		Page: Page{
			PageNumber: PageNumber,
			PageSize:   PageSize,
		},
	})
	t.Log(utils.Format4Output(data, false))

	//api.CreateMerchantGoodsOnStore(&CreateGoodsListToStore{
	//	GoodsName:       "大白菜",
	//	MainPictureURL:  "https://img",
	//	OtherPictureURL: nil,
	//	VideoURL:        "",
	//	Detail:          "这是一颗大白菜",
	//	Cat3Code:        "",
	//	SpecProperty:    nil,
	//	SkuSaleList:     nil,
	//	GoodsType:       "",
	//	SpecCode:        "",
	//	SpecName:        "",
	//	SpecValues:      "",
	//	SpecValueCode:   "",
	//	SpecValueName:   "",
	//	Specification:   "",
	//	MarketPrice:     0,
	//	ThirdSkuCode:    "",
	//})
}

// 门店商品创建
func TestGoMeiStoreAddGoods(t *testing.T) {
	api.CreateGoodsForStore(&CreateGoodsForStoreReq{
		StoreCode:           "GMJ-MS-XOMRF-1J1",
		SkuCode:             "",
		SalePrice:           2.5,
		DeliverType:         "",
		DeliverTemplateCode: "",
	})
}

// 获取门店商品列表
func TestGetSkuList(t *testing.T) {
	data, _ := api.GetMerchantStoreGoodsList(&QueryStoreGoodsListReq{
		GoodsName: "",
		Cat3Code:  "002023002",
		Page:      Page{},
	})
	t.Log(data.Data.Records)

}

// 获取商品详情
func TestGetSkuDetail(t *testing.T) {
	api.QueryMerchantStoreGoodsDetail("11")
}
