package uuptapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
	"testing"
)

var (
	//沙箱环境
	//api = New("ccba8bd4a2d54a2fb6df97e87979f303", "2815a7a1f8e3405d81fd6263683ec4e7", "910a0dfd12bb4bc0acec147bcb1ae246")
	//正式环境
	api         = New("55c4542ae60e4d348edcfc93b06dd302", "76b362c06b1b4baa9e47bab6387a5356", "8d8464e7c9354c1e88a3f5afa2a7922e")
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	//api = New("6705486294797503379", "c1e6c280-e618-4103-9d0a-673bc54fb22e", "5375691", "cabrXQf9eFMVWVYg4hNlwu")
	//token, _ := api.GetAccessToken()
	//api.accessToken = token.BusinessDataObj.AccessToken
}

//
//func TestSignParam(t *testing.T) {
//	testStr := map[string]interface{}{
//		"origin_id":     "T00001",
//		"from_address":  "郑州国际会展中心",
//		"from_usernote": "1层",
//		"to_address":    "商务外环路17号",
//		"to_usernote":   "1楼101",
//	}
//	ans := api.signParam(testStr)
//	fmt.Print(ans)
//}
//func TestRandStr(t *testing.T) {
//	fmt.Print(randStr())
//}
//
//计算运单价格
func TestGetWaybillPrice(t *testing.T) {
	param := &GetOrderPriceReq{
		OriginID:    "T20230114M",
		FromAddress: "万科加州湾V派",
		ToAddress:   "嘉华酒店",
		CityName:    "成都市",
		SendType:    "0",
		ToLat:       "30.691134",
		ToLng:       "104.042307",
		FromLat:     "30.693001",
		FromLng:     "104.04546",
	}
	price := utils.Struct2Map(param, "", false)
	resp, err := api.GetOrderPrice(price)
	fmt.Println(utils.Format4Output(resp, false))
	fmt.Println(err)
}

//发布订单
func TestAddOrder(t *testing.T) {
	param := &AddOrderReq{
		PriceToken:      "0215e844d582477191dfc5f6cd7dcb31",
		OrderPrice:      "9.50",
		BalancePayMoney: "8.07",
		Receiver:        "测试订单",
		ReceiverPhone:   "15680424816,9776",
		CallbackUrl:     uuCallbackURL,
		PushType:        "2", //测试订单
		SpecialType:     "0",
		CallMeWithTake:  "0",
	}
	order := utils.Struct2Map(param, "", false)
	orderCode, originID, err := api.AddOrder(order)
	fmt.Println("orderCode=====", orderCode)
	fmt.Println("originID=====", originID)
	fmt.Println("err=======", err)
}

//获取订单详情
func TestGetOrderDetail(t *testing.T) {
	detail, err := api.GetOrderDetail("23022310041019000003804258")
	fmt.Println(utils.Format4Output(detail, false))
	orderPrice := utils.Str2Float64(detail.OrderPrice)
	priceOff := utils.Str2Float64(detail.PriceOff)
	price := orderPrice - priceOff
	temp := int64(price * 100)
	fmt.Println(temp)
	fmt.Println(err)
}

//取消订单
func TestCancelOrder(t *testing.T) {
	err := api.CancelOrder("23013118111004700001004861", "测试取消")
	fmt.Println(err)
}

//辅助测试
type tStruct struct {
	name string
}

func Test(t *testing.T) {
	zero := 0
	a := int(zero) * 100
	fmt.Printf("a====%d", a)
}

func TestGetOrderLiquidatedDamages(t *testing.T) {
	deductFee, err := api.GetOrderLiquidatedDamages("23022310041019000003804258", "2304613965000093")
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(deductFee)
	}

}
