package ebaiapi

import (
	"fmt"
	"testing"
	"time"

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

const testActivityID = 3000000000517188

func TestActivityCreate(t *testing.T) {
	activityInfo, err := api.ActivityCreate("", testShopBaiduID, 0, &ActivityInfo{
		ActivityName:     "测试活动0403",
		StartTime:        time.Now().Unix(),
		EndTime:          time.Now().Add(24 * time.Hour).Unix(),
		OpenTime:         "22:00",
		CloseTime:        "23:00",
		WeekDay:          "0,1",
		ActivityPlatform: ActivityPFAll,
		DayLimit:         1,
		ActivityDesc:     "测试活动0403描述",
		ShowCategory:     "店铺页活动商品",
		PromotionSkuDesc: "PromotionSkuDesc",
		ActivityType:     ActivityTypeDirectDown,
	})
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(activityInfo, false))
	}
}

func TestActivitySkuAddBatch(t *testing.T) {
	result, err := api.ActivitySkuAddBatch(testActivityID, "", testShopBaiduID, ActivityTypeDirectDown, []*ActivitySkuInfo4Add{
		&ActivitySkuInfo4Add{
			SkuID:          "3594",
			Stock:          9,
			SpecialPrice:   100,
			StoreUserLimit: 9,
		},
	}, true)
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

func TestActivityUpdate(t *testing.T) {
	activityInfo, err := api.ActivityUpdate(6000268610, "", testShopBaiduID, 0, &ActivityInfo{
		ActivityName:     "测试活动0403",
		StartTime:        time.Now().Unix(),
		EndTime:          time.Now().Add(24 * time.Hour).Unix(),
		OpenTime:         "22:00",
		CloseTime:        "23:00",
		WeekDay:          "0,1",
		ActivityPlatform: ActivityPFAll,
		DayLimit:         1,
		ActivityDesc:     "测试活动0403描述",
		ShowCategory:     "店铺页活动商品",
		PromotionSkuDesc: "PromotionSkuDesc",
		ActivityType:     ActivityTypeDirectDown,
	})
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(activityInfo, false))
	}
}

func TestActivityGet(t *testing.T) {
	activityInfo, err := api.ActivityGet(6000000380161091, "", 100000045925, 0)
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(activityInfo, false))
	}
}

func TestActivityDisable(t *testing.T) {
	err := api.ActivityDisable(6000000230771099, "", 42267069437, 0)
	if err != nil {
		t.Fatal(err)
	}
}

func TestActivitySkuList(t *testing.T) {
	activityInfo, err := api.ActivitySkuList(3000000000517188, "", testShopBaiduID, 0, nil, false)
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(activityInfo, false))
	}
}

func TestActMultiChannelQueryIDs(t *testing.T) {
	result, err := api.ActMultiChannelQueryIDs("", 100000045925, "2")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))

}

//2233065924
//2233065928
//2233065934
//2233065955
//2233065956
func TestActMultiChannelQueryInfos(t *testing.T) {
	for _, v1 := range []int64{2233065924} { // , 2233065928, 2233065934, 2233065955, 2233065956
		acts, err := api.ActMultiChannelQueryIDs("", v1, "2")
		fmt.Println(acts)
		if err != nil {
			fmt.Println(err)
		}
		for _, v := range acts {
			_, err2 := api.ActMultiChannelQueryInfos(utils.Int64ToStr(v), "", v1)
			if err2 != nil {
				fmt.Println(err2)
			}
			//t.Log(utils.Format4Output(result, false))
		}
	}

	//_, err2 := api.ActMultiChannelQueryInfos("6000000927837760", "", 2233065924)
	//fmt.Println(err2)
}
