package phpjx

import (
	"git.rosy.net.cn/jx-callback/business/model"
)

var (
	orderStatusMap = map[int]int{
		model.OrderStatusFinishedPickup: 7,
		model.OrderStatusDelivering:     8,
		// 4,
		model.OrderStatusFinished: 3,
		model.OrderStatusCanceled: 3,
	}
)

func translateOrderStatus(status int) (outStatus int) {
	return status //orderStatusMap[status]
}

func (a *API) NotifyOrderStatusChanged(order *model.GoodsOrder) (err error) {
	status := translateOrderStatus(order.Status)
	if status > 0 {
		_, err = a.AccessAPI("orderChangeStatus", map[string]interface{}{
			"orderid": order.VendorOrderID,
			"status":  status,
			"data":    "", //string(utils.MustMarshal(order)),
		}, "")
	}
	return err
}

func (a *API) NotifyAfsOrderStatusChanged(afsOrder *model.AfsOrder) (err error) {
	status := translateOrderStatus(afsOrder.Status)
	if status > 0 {
		_, err = a.AccessAPI("afsOrderChangeStatus", map[string]interface{}{
			"orderid":    afsOrder.VendorOrderID,
			"afsOrderID": afsOrder.AfsOrderID,
			"status":     status,
			"data":       "", //string(utils.MustMarshal(order)),
		}, "")
	}
	return err
}
