package tiktok_api

import (
	"fmt"
	order_logisticsAdd_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/order_logisticsAdd/request"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/globals"
	"testing"
	"time"
)

func TestApi(t *testing.T) {
	a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", "")
	result, err := a.CreateToken("7cfe00c4-f8f0-4f93-992d-baeecd3bef5d")
	globals.SugarLogger.Debugf("%v", utils.Format4Output(result, false))
	globals.SugarLogger.Debugf("%v", utils.Format4Output(err, false))
	globals.SugarLogger.Debugf("%v", utils.Format4Output(a, false))
	globals.SugarLogger.Debugf("%v", utils.Format4Output(a.accessTokenObj, false))
	globals.SugarLogger.Debugf("%v", utils.Format4Output(a.appKey, false))
	globals.SugarLogger.Debugf("%v", utils.Format4Output(a.appSecret, false))
}

func TestQueryOrderDetail(t *testing.T) {
	data, err := a.GetTiktokOrderDetail("6917547162766021688")
	globals.SugarLogger.Debugf("=====%s", utils.Format4Output(data, false))
	globals.SugarLogger.Debugf("=====%s", err)
}

func TestRefaseToken(t *testing.T) {
	//a.CreateToken("c4afc5bc-7ddf-4244-b35a-0c393f3dca32")
	refreshToken, err := a.RefreshToken()
	fmt.Println(refreshToken)
	fmt.Println(err)
	//{"access_token":"c4afc5bc-7ddf-4244-b35a-0c393f3dca32","expires_in":1667203717,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"5a4f9dfe-306b-4bca-8b35-2ae9afc0245e","authority_id":""}
	//{"access_token":"37f41ac7-49ac-4848-a0ee-ea86bb0dfd9f","expires_in":519389,"scope":"SCOPE","shop_id":"","shop_name":"抖店开放平台测试专用店","refresh_token":"3dd8f638-fdf1-46e7-b974-88df382f03c6","authority_id" :""}
}

func TestTimeNow(t *testing.T) {
	h, m, s := time.Now().Clock()
	fmt.Println(h, m, s)
}

func TestSendGoods(t *testing.T) {
	param := &order_logisticsAdd_request.OrderLogisticsAddParam{
		OrderId:          "5013254696638589999",
		Company:          "",
		CompanyCode:      "chengdouruoxi",
		LogisticsCode:    "5013254696638589999",
		IsRefundReject:   false,
		IsRejectRefund:   false,
		SerialNumberList: nil,
		AddressId:        0,
		StoreId:          63520894,
	}
	a.OrderDelivering(param)
}

// 创建物流token
func TestCreateExpss(t *testing.T) {
	a := NewExpress("7153997323561879075", "3517d3ea-b96b-4379-a7a4-2d9389e8ffeb", "")
	a.CreateToken()
}

// 同意退货申请
func TestReturnGoodsToWareHouseSuccess(t *testing.T) {
	token := `{"access_token":"60f530b2-9ab6-4723-b487-c094918f0d21","expires_in":1666257163,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"1220666a-5e88-458c-a8c0-06d949fbbd3f","authority_id":""}`
	a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
	a.ReturnGoodsToWareHouseSuccess("7154200345302827303")
}

// 多订单同一个物流包裹
func TestLogisticsAddSinglePack(t *testing.T) {
	a.LogisticsAddSinglePack()
}

func TestYearDay(t *testing.T) {
	fmt.Println(time.Now().YearDay())
}

func TestApplyMarketAfterSale(t *testing.T) {
	a.ApplyMarketAfterSale(4994383659114192282, 2, 3)
}

func TestOrderStatusAndPsInfo(t *testing.T) {
	a := NewExpress("7153997323561879075", "3517d3ea-b96b-4379-a7a4-2d9389e8ffeb", "")
	a.CreateToken()
	param := make(map[string]interface{}, 0)
	param["third_carrier_order_id"] = "4996521792598113690"
	param["logistics_context"] = "呼叫骑手"
	param["opcode"] = "CALL_RIDER"
	param["courier_name"] = ""
	param["courier_phone"] = ""
	a.OrderStatusAndPsInfo(param)
}

func TestMap(t *testing.T) {
	fmt.Println((57 & 2) != 0)
}
