package weimobapi

import (
	"testing"

	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
)

func TestQueryGoodsList(t *testing.T) {
	//result, totalCount, err := api.QueryGoodsList(1, 20, nil, nil)
	//if err != nil {
	//	t.Fatal(err)
	//}
	//baseapi.SugarLogger.Debug(totalCount)
	//baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestQueryGoodsDetail(t *testing.T) {
	result, err := api.QueryGoodsDetail(21128350148)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestQueryCategoryTree(t *testing.T) {
	result, err := api.QueryCategoryTree()
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestQueryChildrenCategory(t *testing.T) {
	result, err := api.QueryChildrenCategory(1)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestQueryClassifyInfoList(t *testing.T) {
	result, err := api.QueryClassifyInfoList()
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestAddClassify(t *testing.T) {
	result, err := api.AddClassify("我的测试子分类1", 442315148, "")
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestFindDeliveryTypeList(t *testing.T) {
	result, err := api.FindDeliveryTypeList(0)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestAddGoods(t *testing.T) {
	result, skuMap, err := api.AddGoods("SPU1", "测试土豆", false, []string{"https://image-c.weimobwmc.com/openruntime/8ff6950112974cff8b2f1ae1634c074d.png"}, "测试的高级土豆", true, 1, 35,
		[]int64{438963248},
		&PendingSaveB2CGoodsVo{
			FreightTemplateId:  6537248,
			DeliveryTypeIdList: []int64{177445},
			B2cGoodsType:       0,
		},
		[]map[string]interface{}{
			map[string]interface{}{
				KeyOuterSkuCode: "SKU2",
				KeyImageURL:     "https://image-c.weimobwmc.com/openruntime/8ff6950112974cff8b2f1ae1634c074d.png",
				KeySalePrice:    12.34,
				KeyEditStockNum: 99999,
				KeyB2cSku: &PendingSaveB2CSkuVo{
					Weight: 0.12,
				},
			},
		}, nil)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
	baseapi.SugarLogger.Debug(utils.Format4Output(skuMap, false))
}

func TestUpdateGoods(t *testing.T) {
	result, skuMap, err := api.UpdateGoods(20446200148, "测试土豆修改", false, []string{"https://image-c.weimobwmc.com/openruntime/8ff6950112974cff8b2f1ae1634c074d.png"}, "测试的高级土豆", true, 1, 35,
		[]int64{438963248},
		&PendingSaveB2CGoodsVo{
			FreightTemplateId:  6537248,
			DeliveryTypeIdList: []int64{177445},
			B2cGoodsType:       0,
		},
		[]map[string]interface{}{
			map[string]interface{}{
				KeyOuterSkuCode: "SKU22",
				KeyImageURL:     "https://image-c.weimobwmc.com/openruntime/8ff6950112974cff8b2f1ae1634c074d.png",
				KeySalePrice:    12.34,
				KeyEditStockNum: 99999,
				KeyB2cSku: &PendingSaveB2CSkuVo{
					Weight: 0.12,
				},
			},
		}, nil)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
	baseapi.SugarLogger.Debug(utils.Format4Output(skuMap, false))
}

func TestUploadImgByURL(t *testing.T) {
	result, err := api.UploadImgByURL("http://www.jxc4.com/static/img/logo200.png", "")
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}

func TestFindFreightTemplateList(t *testing.T) {
	result, err := api.FindFreightTemplateList(0)
	if err != nil {
		t.Fatal(err)
	}
	baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}
