package jdapi

import (
	"testing"
	"time"

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

func TestFakeOrderQuery(t *testing.T) {
	api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")

	retVal, err := api.FakeQuerySingleOrder("2002984074001021")
	t.Log(utils.Format4Output(retVal, false))
	if err != nil {
		t.Error(err)
	}
	if false {
		t.Log(utils.Format4Output(retVal, false))
	}
}

func TestFakeBatchUpdateCurrentQtys(t *testing.T) {
	api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")

	retVal, err := api.FakeBatchUpdateCurrentQtys("", "", "11943257", []*SkuStock{
		&SkuStock{
			OutSkuId: "2029937911",
			StockQty: 88,
		},
	}, "test")
	t.Log(utils.Format4Output(retVal, false))
	if err != nil {
		t.Error(err)
	}
	if false {
		t.Log(utils.Format4Output(retVal, false))
	}
}

func TestFakeBatchUpdateVendibility(t *testing.T) {
	api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")

	retVal, err := api.FakeBatchUpdateVendibility("", "", "11943257", []*StockVendibility{
		&StockVendibility{
			OutSkuId: "2029937911",
			DoSale:   true,
		},
	}, "test")
	t.Log(utils.Format4Output(retVal, false))
	if err != nil {
		t.Error(err)
	}
	if false {
		t.Log(utils.Format4Output(retVal, false))
	}
}

func TestFakeUpdateVendorStationPrice(t *testing.T) {
	api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")

	retVal, err := api.FakeUpdateVendorStationPrice("", "", "11943257", []*SkuPriceInfo{
		&SkuPriceInfo{
			OutSkuId: "2029937911",
			Price:    4567,
		},
	})
	t.Log(utils.Format4Output(retVal, false))
	if err != nil {
		t.Error(err)
	}
	if false {
		t.Log(utils.Format4Output(retVal, false))
	}
}

func TestFakeCreatePromotionSingle(t *testing.T) {
	api := NewFakeJD("ndslkv9asl@djf_n7askdjfk$", "http://test.jxc4.com/qqqq")

	infoId, err := api.CreatePromotionInfosSingle("测试1", time.Now(), time.Now().Add(24*time.Hour), "", "", "")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(infoId)
	err = api.CreatePromotionRulesSingle(infoId, "", 1, 1, 1, 1, "")
	if err != nil {
		t.Fatal(err)
	}
	skuInfos, err := api.CreatePromotionSkuSingle(infoId, "", []*PromotionSku{
		&PromotionSku{
			OutSkuID:       "2216",
			StationNo:      11943257,
			PromotionPrice: 500,
			LimitSkuCount:  2,
		},
	}, "")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(skuInfos)
	err = api.ConfirmPromotionSingle(infoId, "", "")
	if err != nil {
		t.Fatal(err)
	}
}
