package fnpsapi

import (
	"testing"
	"time"

	"git.rosy.net.cn/baseapi/utils"
)

func TestQueryOrder(t *testing.T) {
	result, err := api.QueryOrder("134420892247000001")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestCreateOrder(t *testing.T) {
	params := &CreateOrderParam{
		PartnerOrderCode: "2140252158517300353",
		NotifyURL:        "https://callback.test.jxc4.com/fn/msg",
		ChainStoreCode:   "667281",
		OrderType:        1, //即时达
		TransportInfo: &TransportInfo{
			TransportName:      "测试西南交大店",
			TransportAddress:   "成都市金牛区交大路银桂桥二巷60号",
			TransportLongitude: 104.047773,
			TransportLatitude:  30.695838,
			PositionSource:     3,
			TransportTel:       "18160030913",
		},
		OrderAddTime:       time.Now().UnixNano() / 1e6,
		OrderTotalAmount:   12,
		OrderActualAmount:  10,
		OrderWeight:        1.2,
		OrderRemark:        utils.FilterMb4("客户电话：18160030913,测试取货失败或配送遇到问题请联系18048531223，禁止未配送直接完成定单！"),
		IsInvoiced:         0,
		OrderPaymentStatus: 1,
		OrderPaymentMethod: 1,
		IsAgentPayment:     0,
		GoodsCount:         2,
		ReceiverInfo: &ReceiverInfo{
			ReceiverName:         "苏尹岚",
			ReceiverAddress:      "武侯大道金色花园A区",
			ReceiverLongitude:    104.01459,
			ReceiverLatitude:     30.636258,
			ReceiverPrimaryPhone: "18160030913",
			ReceiverSecondPhone:  "18160030913",
			PositionSource:       3,
		},
		SerialNumber: "测试1#",
	}
	var skuInfo []*ItemsJSON
	// for _, v := range order.Skus {
	skuInfo = append(skuInfo, &ItemsJSON{
		ItemID:          "30677",
		ItemName:        "测试商品",
		ItemQuantity:    1,
		ItemPrice:       3.6,
		ItemActualPrice: 2,
	})
	// }
	params.ItemsJSON = skuInfo
	//要求饿百的订单要传来源
	// if order.VendorID == model.VendorIDEBAI {
	// 	params.OrderSource = "109"
	// 	params.ChannelOrderCode = order.VendorOrderID
	// }
	err := api.CreateOrder(params)
	if err != nil {
		t.Fatal(err)
	}
	// t.Log(utils.Format4Output(result, false))
}

func TestComplaintRider(t *testing.T) {
	err := api.ComplaintRider("2118635456000161", 130)
	if err != nil {
		t.Fatal(err)
	}
	// t.Log(utils.Format4Output(result, false))
}

func TestCancelOrder(t *testing.T) {
	err := api.CancelOrder(&CancelOrderParam{
		PartnerOrderCode: "89296492736359287",
	})
	if err != nil {
		t.Fatal(err)
	}
	// t.Log(utils.Format4Output(result, false))
}
