package ebaiapi

import (
	"fmt"
	"git.rosy.net.cn/jx-callback/globals"
	"strings"
	"testing"
	"time"

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

func TestCancelOrder(t *testing.T) {
}

func TestOrderGet(t *testing.T) {
	result, err := api.OrderGet("4054310134272361023")
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

func TestOrderAgreePartRefund(t *testing.T) {
	param := &RefundOrderExamine{
		ReverseOrderId: "",
		OrderId:        "4016410136052874965",
		IdempotentId:   utils.Int64ToStr(time.Now().UnixNano()),
		ActionType:     RefundTypeRefuse,
		ReasonCode:     "7001",
		ReasonRemarks:  "1111",
	}
	refundProductList := make([]*RefundProductList, 0, 0)
	date, _, _ := api.GetReverseOrder("4016410136052874965")
	for _, v := range date {
		v2 := v.(map[string]interface{})
		refundProduct := &RefundProductList{
			SubBizOrderId: v2["sub_biz_order_id"].(string),
			PlatformSkuId: utils.Int64ToStr(utils.Interface2Int64WithDefault(v2["platform_sku_id"], 0)),
		}
		param.ReverseOrderId = utils.Int64ToStr(utils.MustInterface2Int64(v2["refund_order_id"]))
		switch utils.MustInterface2Int64(v2["fund_calculate_type"]) {
		case 0:
			refundProduct.Number = utils.Int64ToStr(utils.MustInterface2Int64(v2["refund_quantity"]))
		case 1:
			refundProduct.RefundAmount = utils.Int64ToStr(utils.MustInterface2Int64(v2["refund_user_amount"]))
		}
		refundProductList = append(refundProductList, refundProduct)
	}
	param.RefundProductList = refundProductList

	err := api.OrderDisagreeReturnGoods(param)
	globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
}

func TestOrderAgreeRefund(t *testing.T) {
	err := api.OrderAgreeRefund(&RefundOrderExamine{
		ReverseOrderId: "2308279044977730245",
		OrderId:        "4002450124418844395",
		IdempotentId:   utils.Int64ToStr(time.Now().UnixNano()),
		ActionType:     "1",
		ReasonRemarks:  "",
	})
	fmt.Println(err)
}

func Test11111(t *testing.T) {
	fmt.Println(strings.Contains("[隐私保护]顾客地址已隐藏，您可登录饿了么商家端或骑手端查看", "隐私保护"))
}

func TestGetReverseOrder(t *testing.T) {
	date, isAll, err := api.GetReverseOrder("4037190131865481753")
	fmt.Println(isAll)
	fmt.Println(err)
	for _, v := range date {
		fmt.Println(v)
	}
}
func TestOrderGet2(t *testing.T) {
	result, err := api.OrderGet2("4043790061034194507")
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

func TestOrderStatusGet(t *testing.T) {
	result, err := api.OrderStatusGet("1576493808229489038")
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}
func TestOrderList(t *testing.T) {
	result, err := api.OrderList("300104", 32267046052, utils.Str2Time("2022-08-22").Unix(), utils.Str2Time("2022-09-08").Unix(), 0, 1)
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

func TestOrderListAll(t *testing.T) {
	result, err := api.OrderListAll("", 32267046052, utils.Str2Time("2022-09-01").Unix(), utils.Str2Time("2022-09-08").Unix(), 0)
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

func TestOrderPartRefundGet(t *testing.T) {
	result, err := api.OrderPartRefundGet("4033790060039747082")
	if err != nil {
		t.Fatal(err)
	} else {
		t.Log(utils.Format4Output(result, false))
	}
}

// func TestOrderPartRefundGet2(t *testing.T) {
// 	result, err := api.OrderPartRefundGet2("1557459492221457830")
// 	if err != nil {
// 		t.Fatal(err)
// 	} else {
// 		t.Log(utils.Format4Output(result, false))image/upload
// 	}
// }

func TestOrderConfirm(t *testing.T) {
	err := api.OrderConfirm("4087880039095667221")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderPickComplete(t *testing.T) {
	err := api.OrderPickComplete("4087880039095667221")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderCallDelivery(t *testing.T) {
	err := api.OrderCallDelivery("1556617836226053651")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderSwitchselfdelivery(t *testing.T) {
	err := api.OrderSwitchselfdelivery("1574550169196474502")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderComplete(t *testing.T) {
	err := api.OrderComplete("4016410136237474551", "")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderPrivateInfo(t *testing.T) {
	_, err := api.OrderPrivateInfo("1542178206811884")
	if err != nil {
		t.Fatal(err)
	}
	// t.Log(result)
}

func TestOrderDeliveryGet(t *testing.T) {
	result, err := api.OrderDeliveryGet("4053750050397193755")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(result)
}

func TestSmartOrderIdConvert(t *testing.T) {
	result, err := api.SmartOrderIdConvert("3035779376398878822")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(result)
}

func TestOrderPartRefund(t *testing.T) {
	err := api.OrderPartRefund("3035779376398878822", []*RefundSku{
		&RefundSku{
			CustomeSkuID: "",
			Number:       "1",
		},
	})
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderCancel(t *testing.T) {
	err := api.OrderCancel("2122788271803194389", CancelTypeCustom, "admin")
	if err != nil {
		t.Fatal(err)
	}
}

func TestOrderQueryAcceptancecode(t *testing.T) {
	err := api.OrderQueryAcceptancecode("5021871103848829132")
	if err != nil {
		t.Fatal(err)
	}
}

func TestAPI_OrderselfDeliveryStateSync(t *testing.T) {
	err := api.OrderselfDeliveryStateSync("4457139638483820157", "199999999999")
	if err != nil {
		t.Fatal(err)
	}
}

func TestForAA(t *testing.T) {

	var a = []int64{6044969,
		6043622,
		6044971,
		6042562,
		31728,
		31729,
		32143,
		32142,
		6043605,
		6043604,
		6042743,
		30226,
		30225,
		6043959,
		6043960,
		6042349,
		6042296,
		31882,
		31871,
		6042704,
		6039499,
		30415,
		30414,
		32364,
		32363,
		6043603,
		6043602,
		30224,
		30223,
		6042284,
		30215,
		30214,
		6039424,
		31235,
		30368,
		30370,
		30369,
		30183,
		30182,
		6042733,
		6042737,
		30237,
		30236,
		6042287,
		30213,
		6042288,
		30233,
		30207,
		30206,
		30190,
		30189,
		6042167,
		6042166,
		30413}

	var cc = ""
	for _, v := range a {
		if v != 30413 {
			cc += utils.Int64ToStr(v) + ","
		}
		cc += utils.Int64ToStr(v)
	}
	fmt.Println(cc)
}

func TestOnline(t *testing.T) {
	fmt.Println(0&(2|4|32) != 0)
	fmt.Println(MergeStoreStatus(-2, 1))
}

// 合并得到最终的门店状态
func MergeStoreStatus(status int, vendorStatus int) int {
	if status < vendorStatus {
		return status
	}
	return vendorStatus
}

func Test223(t *testing.T) {
	var statuss []int
	if err := utils.UnmarshalUseNumber([]byte("[20]"), &statuss); err != nil {
		fmt.Println(err)
	}
	fmt.Println(statuss)
}
