package dadaapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/jx-callback/business/model"
	"go.uber.org/zap"
	"testing"
)

//
//import (
//	"net/http"
//	"testing"
//
//	"git.rosy.net.cn/baseapi"
//
//	"git.rosy.net.cn/baseapi/utils"
//	"go.uber.org/zap"
//)
//
var (
	dadaapi     *API
	sugarLogger *zap.SugaredLogger
	testOrder   *OperateOrderParams
)

//
//const (
//	testShopNo = "11047059"
//)
//
func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	// sandbox
	// dadaapi = New("dada9623324449cd250", "30c2abbfe8a8780ad5aace46300c64b9", "73753", "http://callback.jxc4.com/dada/order", false)

	// prod
	dadaapi = New("dada154e2a41fd6cef3", "7f97d8f258b70b450f04e7ab274ed8f8", "6660", "http://callback.jxc4.com/dadadelivery/msg", true)

	// prod
	//testOrder = &OperateOrderParams{
	//	ShopNo:          testShopNo,
	//	OriginID:        "234242342",
	//	CityCode:        "028",
	//	CargoPrice:      12.34,
	//	IsPrepay:        1,
	//	ReceiverName:    "我是谁",
	//	ReceiverAddress: "九里堤",
	//	ReceiverLat:     30.74631,
	//	ReceiverLng:     103.99112,
	//	ReceiverPhone:   "12812345678",
	//}

}

func TestComplaintRider(t *testing.T) {
	err := dadaapi.ComplaintRider("5000952191610480635", 69)
	fmt.Println(err)
}
func TestComplaintList(t *testing.T) {
	dadaapi.ComplaintList()
}

func Test222222(t *testing.T) {
	a := 57
	fmt.Println(a&(model.SyncFlagNewMask|model.SyncFlagStoreName) != 0)
	fmt.Println((a & 2) != 0)
	fmt.Println((a & 4) != 0)
}

//
//func TestTest(t *testing.T) {
//	sugarLogger.Debug(utils.GetCurTimeStr())
//}
//
//func TestSignCallback(t *testing.T) {
//	sampleData := `{"signature":"5a277f2519b6011028ff541fb09b8553","client_id":"275000419162381","order_id":"234242342","order_status":1,"cancel_reason":"","cancel_from":0,"dm_id":0,"update_time":1529564947}`
//	mapData := make(map[string]interface{})
//	utils.UnmarshalUseNumber([]byte(sampleData), &mapData)
//	sign := dadaapi.signCallbackParams(mapData)
//	if sign != mapData["signature"] {
//		t.Fatal("sign is not correct")
//	}
//}
//
//func TestAccessAPI(t *testing.T) {
//	body := make(map[string]interface{})
//	body["order_id"] = "fakeorderid"
//	result, err := dadaapi.AccessAPI("api/order/status/query", body)
//
//	failed := true
//	if err != nil {
//		if err2, ok := err.(*utils.ErrorWithCode); ok {
//			if err2.IntCode() != ResponseCodeSignErr {
//				failed = false
//			}
//		}
//	} else {
//		failed = false
//	}
//
//	if failed {
//		t.Fatalf("Error when accessing api result:%v, error:%v", result, err)
//	}
//}
//
//func TestGetCites(t *testing.T) {
//	result, err := dadaapi.GetCities()
//	if err != nil {
//		t.Fatal(err.Error())
//	}
//	failed := true
//	for _, city := range result {
//		if city.CityCode == "028" {
//			failed = false
//		}
//	}
//
//	if failed {
//		t.Fatal("failed")
//	}
//}
//
//func TestGetReasons(t *testing.T) {
//	result, err := dadaapi.GetCancelReasons()
//	if err != nil {
//		t.Fatal(err.Error())
//	}
//	// baseapi.SugarLogger.Debug(result)
//	failed := true
//	for _, reason := range result {
//		if reason.ID == 1 {
//			failed = false
//		}
//	}
//
//	if failed {
//		t.Fatal("failed")
//	}
//}
//
//func TestAddOrder(t *testing.T) {
//	result, err := dadaapi.AddOrder(testOrder)
//	if err != nil {
//		t.Fatal(err.Error())
//	}
//	t.Fatal(result)
//}
//
//func TestReaddOrder(t *testing.T) {
//	result, err := dadaapi.ReaddOrder(testOrder)
//	if err != nil {
//		t.Fatal(err.Error())
//	}
//	baseapi.SugarLogger.Debug(result)
//}
//
//func TestCancelOrder(t *testing.T) {
//	result, err := dadaapi.CancelOrder("234242342", ReasonIDClientDontWantItAnymore, "")
//	if err != nil {
//		t.Fatal(err.Error())
//	}
//	baseapi.SugarLogger.Debug(result)
//}
//
//func TestCallbackMsgPlayback(t *testing.T) {
//	baseURL := "http://callback.test.jxc4.com:8080/"
//	playbackData := [][]string{
//		[]string{
//			"{\"signature\":\"2b10053038eef28af360fa2603d59fd1\",\"client_id\":\"275159553154971\",\"order_id\":\"815433510000122\",\"order_status\":1,\"cancel_reason\":\"\",\"cancel_from\":0,\"dm_id\":0,\"update_time\":1530171995}",
//			baseURL + "dadadelivery/msg",
//		},
//		[]string{
//			"{\"signature\":\"14cb9d55179d47de73e09d3b5e800fea\",\"client_id\":\"275159553154971\",\"order_id\":\"815433510000122\",\"order_status\":2,\"cancel_reason\":\"\",\"cancel_from\":0,\"dm_id\":4690995,\"dm_name\":\"王杰\",\"dm_mobile\":\"15982842356\",\"update_time\":1530172054}",
//			baseURL + "dadadelivery/msg",
//		},
//		[]string{
//			"{\"signature\":\"1058519a18dd8ee8ba6a1638e53bed66\",\"client_id\":\"275159553154971\",\"order_id\":\"815433510000122\",\"order_status\":3,\"cancel_reason\":\"\",\"cancel_from\":0,\"dm_id\":4690995,\"dm_name\":\"王杰\",\"dm_mobile\":\"15982842356\",\"update_time\":1530173065}",
//			baseURL + "dadadelivery/msg",
//		},
//		[]string{
//			"{\"signature\":\"9c7a5d72d4e9bdea7b452f38e5c5a0dc\",\"client_id\":\"275159553154971\",\"order_id\":\"815433510000122\",\"order_status\":4,\"cancel_reason\":\"\",\"cancel_from\":0,\"dm_id\":4690995,\"dm_name\":\"王杰\",\"dm_mobile\":\"15982842356\",\"update_time\":1530173559}",
//			baseURL + "dadadelivery/msg",
//		},
//	}
//	for _, v := range playbackData {
//		_, err := utils.SendFakeRequest(http.MethodPost, v[1], v[0], "application/json; charset=utf-8")
//		if err != nil {
//			t.Fatal(err)
//		}
//	}
//}
