package jdapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi/utils"
	"testing"
)

func TestQuerySingleOrder(t *testing.T) {
	retVal, err := api.QuerySingleOrder("2226834717000174")
	t.Log(utils.Format4Output(retVal, false))
	if err != nil {
		t.Error(err)
	}
	if false {
		t.Log(utils.Format4Output(retVal, false))
	}
	//retVal, err = api.QuerySingleOrder("999999")
	//if err == nil {
	//	t.Error("应该找不到这个订单！")
	//}
}

func TestPickUp(t *testing.T) {
	detile, err := api.OrderJDZBSelfDelivery("2223127747000074", "刘磊")
	fmt.Println("detail===", detile)
	fmt.Println("detail===", err)
}

func TestOrderQuery(t *testing.T) {
	jdParams := map[string]interface{}{
		"deliveryStationNo":       "11954632",
		"orderPurchaseTime_begin": "2022-11-05 00:00:00",
	}
	result, totalCount, err := api.OrderQuery(jdParams)
	if err != nil {
		t.Fatalf("OrderQuery return error:%v", err)
	}
	t.Log(utils.Format4Output(result, false))
	if len(result) == 0 || totalCount == 0 {
		t.Fatal("OrderQuery return empty data")
	}
	buyerCityOk := false
	orderInfo, _ := result[0].(map[string]interface{})
	if buyerCity1, ok := orderInfo["buyerCity"]; ok {
		if buyerCity, ok := buyerCity1.(string); ok && buyerCity == "2376" {
			buyerCityOk = true
		}
	}

	if !buyerCityOk {
		t.Fatal("OrderQuery get data wrong")
	}
}

func TestOrderAcceptOperate(t *testing.T) {
	err := api.OrderAcceptOperate("2318183905000222", true, "")
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestMyself(t *testing.T) {
	detail, errr := api.OrderJDZBStoreDelivery("2318183905000222", "liulei")
	fmt.Println(detail)
	fmt.Println(errr)
}

func TestOrderJDZBDelivery(t *testing.T) {
	result, err := api.OrderJDZBDelivery("911350836000622", "")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestModifySellerDelivery(t *testing.T) {
	result, err := api.ModifySellerDelivery("2320085686000392", "")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestOrderSerllerDelivery(t *testing.T) {
	result, err := api.OrderSerllerDelivery("2214740704000086", "自配送")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestDeliveryEndOrder(t *testing.T) {
	result, err := api.DeliveryEndOrder("2326939731000094", "")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestGetAfsService(t *testing.T) {
	result, err := api.GetAfsService("2225735125000294")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(utils.Format4Output(result, false))
}

func TestGetAfsService2(t *testing.T) {
	result, err := api.GetAfsService2("34778110")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(utils.Format4Output(result, false))
}

func TestOrderShoudSettlementService2(t *testing.T) {
	result, err := api.OrderShoudSettlementService2("2305327970000571")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(utils.Format4Output(result, false))
}

func TestOrderAddTips(t *testing.T) {
	err := api.OrderAddTips("2116212802000361", 100, "jxadmin")
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestOrderQuery2(t *testing.T) {
	//orderList, _, err := api.OrderQuery2(&OrderQueryParam{
	//	OrderPurchaseTimeBegin: "2022-11-05 00:00:00",
	//	OrderPurchaseTimeEnd:   "2022-11-05 23:59:59",
	//	DeliveryStationNo:      "11954632",
	//	PageNo:                 1,
	//	PageSize:               99999,
	//})
	orderList, _, err := api.OrderQuery2(&OrderQueryParam{
		OrderID: 2318183905000222,
	})
	t.Log(utils.Format4Output(orderList, false))
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestGetByOrderNoForOaos(t *testing.T) {
	orderList, err := api.GetByOrderNoForOaos("2320085686000392")
	t.Log(utils.Format4Output(orderList, false))
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestGetByOrderNoForOaosNew(t *testing.T) {
	orderList, err := api.GetByOrderNoForOaosNew("2108504597000531")
	t.Log(utils.Format4Output(orderList, false))
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestCheckSelfPickCode(t *testing.T) {
	err := api.CheckSelfPickCode("135246", "2027170805000062", "jxadmin")
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestProcessQuestionPic(t *testing.T) {
	for _, v := range [][]string{
		[]string{
			"http://img10.360buyimg.com/o2o/jfs/a.jpg",
			",,,jfs/a.jpg",
		},
		[]string{
			"http://img10.360buyimg.com/o2o/jfs/a.jpg,https://img10.360buyimg.com/o2o/jfs/b.jpg",
			" ,  ,,  jfs/a.jpg,https:jfs/b.jpg",
		},
		[]string{
			"https://img10.360buyimg.com/o2o/jfs/a.jpg",
			",https:jfs/a.jpg",
		},
		[]string{
			"",
			",https:",
		},
	} {
		str := ProcessQuestionPic(v[1])
		if str != v[0] {
			t.Fatalf("%s, desired:%s, but its:%s", v[1], v[0], str)
		}
	}
}

func TestCancelAndRefund(t *testing.T) {
	err := api.CancelAndRefund("2116133812000152", "jxadmin", "协商一致")
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestGenerateReverseOrder(t *testing.T) {
	err := api.GenerateReverseOrder("2114820876000231", []*RefDiffAdjustSkuList{
		&RefDiffAdjustSkuList{
			SkuId:           "2036475569",
			SkuActualWeight: 230,
		},
	})
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestConfirmReceiveGoods(t *testing.T) {
	err := api.ConfirmReceiveGoods("2115980474000061")
	if err != nil {
		t.Fatal(err.Error())
	}
}

func TestAfsOpenApprove(t *testing.T) {
	err := api.AfsOpenApprove("34290642", 1, "同意退款", "jxadmin-13689038670")
	if err != nil {
		t.Fatal(err.Error())
	}
}
