package sfps2

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

var api = New(AppID, AppKey)

const (
	//正式环境
	AppID2  = 1663705444
	AppKey2 = "600e22db5deb6402e527e58f0d6636a0"

	AppID         = 1663705378                         //测试开发者ID
	AppKey        = "0838426b310fd2530c57dd6e770ddff1" //测试开发者密钥
	TestSFStoreID = "3243279847393"                    //open测试平台型店铺
)

//预下单
func TestPreCreateOrder(t *testing.T) {
	param := &PreCreateOrderReq{
		DevId:           AppID,
		ShopId:          TestSFStoreID,
		UserLng:         "116.339392",
		UserLat:         "40.002349",
		UserAddress:     "北京市海淀区学清嘉创大厦A座15层",
		Weight:          1000,
		ProductType:     4,
		PushTime:        1684996039,
		ShopType:        1,
		LbsType:         LbsTypeGD,
		RiderPickMethod: 1,
		ReturnFlag:      1,
		//IsAppoint:   0,
		//AppointType:      2,
		//ExpectPickupTime: int64(time.Now().Unix()),
		//RiderPickMethod: 1,
		//MultiPickupInfo: []*MultiPickupInfo{{
		//	PickupShopAddress: "海淀区清河龙岗路51号清润家园小区 永辉",
		//	PickupLat:         "40.030613",
		//	PickupLng:         "116.354787",
		//}},
	}
	resp, err := api.PreCreateOrder(param)
	fmt.Println(resp)
	fmt.Println(err)
}

//正式下单
func TestCreateOrder(t *testing.T) {
	param := &CreateOrderReq{
		DevId:         AppID,
		ShopId:        TestSFStoreID,
		ShopOrderId:   "20230525Test",
		OrderSequence: "测试",
		OrderSource:   OrderSourceELM,
		OrderTime:     1684997166,
		PushTime:      1684997166,
		Version:       19,
		ReturnFlag:    511,
		Receive: &ReceiveAddress{
			UserLng:     "116.339392",
			UserLat:     "40.002349",
			UserAddress: "北京市海淀区学清嘉创大厦A座15层",
			UserName:    "杨玺",
			UserPhone:   "17236456352",
		},
		OrderDetail: &OrderDetail{
			TotalPrice:     890,
			ProductType:    4,
			WeightGram:     390,
			ProductNum:     1,
			ProductTypeNum: 1,
			ProductDetail: []*ProductDetail{{
				ProductName: "新鲜水果拼盘",
				ProductNum:  1,
			}},
		},
		RiderPickMethod: 1,
	}
	sfOrderID, sfBillID, totalPrice, err, _ := api.CreateOrder(param)
	fmt.Println(sfOrderID, sfBillID)
	fmt.Println(totalPrice)
	fmt.Println(err)
}

//预取消订单
func TestPreCancelOrder(t *testing.T) {
	resp, err := api.PreCancelOrder("JS4157236257228")
	fmt.Println(resp)
	fmt.Println(err)
}

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

//订单实时信息查询
func TestGetOrderStatus(t *testing.T) {
	resp, err := api.GetOrderStatus("JS4157016257273")
	fmt.Println(utils.Format4Output(resp, false))
	fmt.Println(err)
}

//
func TestGetRiderLatestPosition(t *testing.T) {
	resp, err := api.GetRiderLatestPosition("JS4157016257273")
	fmt.Println(utils.Format4Output(resp, false))
	fmt.Println(err)
}

func TestNew(t *testing.T) {
	te := strings.Split("113.71776,34.767501", ",")
	if len(te) > 0 {
		fmt.Println(te[0], te[1])
		lng := utils.Str2Float64(te[0])
		lat := utils.Str2Float64(te[1])
		fmt.Println(lng, lat)
	}
}
