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) {
	result, err := a.CreateToken("28d698bb-fb04-4904-8f3f-7cfdca819ce5")
	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("6940698406196810794")
	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) {
	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) {
	//appKey := `7152420904331429407`                     // 暂时定死
	//appSecret := `cc7ba367-2394-4cbb-81c6-26f0e929d1c6` // 暂时定死
	//token := `{"access_token":"4a543151-f8fd-43d5-9c34-d19fe11fc51c","expires_in":1694069036,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"5a2aaca1-42f7-4b83-9358-8ed5d1d4bcd6","authority_id":""}`
	//a2 := NewExpress("7152420904331429407", "cc7ba367-2394-4cbb-81c6-26f0e929d1c6", token)
	//a2.CreateToken()
	riderInfo := &utils.RiderInfo{
		OrderId:               "6923516654669862544",
		ThirdCarrierOrderId:   "6923516654669862544",
		CourierName:           "刘磊",
		CourierPhone:          "18981810340",
		LogisticsProviderCode: utils.MyselfPsCode,
		LogisticsStatus:       0,
		LogisticsContext:      "商家自配送,已送达",
		Latitude:              "109.8779542115685",
		Longitude:             "31.078094805818893",
		OpCode:                TiktokLogisticsDELIVERED,
	}

	a.OrderStatusAndPsInfoNew(utils.Struct2MapByJson(riderInfo), "")
}

func TestGetRefundAddressId(t *testing.T) {
	a.GetRefundAddressId(64250734)
}
