package mtwmapi

import (
	"testing"

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

func TestShippingSave(t *testing.T) {
	err := api.ShippingSave(testPoiCode, `[{"x":39941199,"y":116385384},{"x":39926983,"y":116361694},{"x":39921586,"y":116398430}]`, 0, 0)
	if err != nil {
		t.Fatal(err)
	}
}

func TestShippingList(t *testing.T) {
	result, err := api.ShippingList("32054188")
	if err != nil {
		t.Fatal(err)
	}
	shippingList := make([]ShippingList, 0, 0)
	for _, v := range result {
		shippingList = append(shippingList, ShippingList{
			TimeRange:   utils.Interface2String(v["time_range"]),
			MinPrice:    utils.MustInterface2Float64(v["min_price"]),
			ShippingFee: utils.MustInterface2Float64(v["shipping_fee"]),
		})
	}
	t.Log(utils.Format4Output(shippingList, false))
	t.Log(utils.Format4Output(result, false))
}

type ShippingList struct {
	TimeRange   string  `json:"time_range"`   // 配送生效时间范围
	MinPrice    float64 `json:"min_price"`    // 最小起送价
	ShippingFee float64 `json:"shipping_fee"` // 配送费
}

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