package gome_live_show

import (
	"net/url"

	"git.rosy.net.cn/jx-callback/globals"

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

type CallBackInfo struct {
	AppID     string `json:"app_id"`
	Data      string `json:"data"`
	Salt      int    `json:"salt"`
	Signature string `json:"signature"`
}

type WayBillInfo struct {
	PartnerOrderCode   string `json:"partner_order_code"`
	OrderStatus        int    `json:"order_status"`
	PushTime           int64  `json:"push_time"`
	CarrierDriverName  string `json:"carrier_driver_name"`
	CarrierDriverPhone string `json:"carrier_driver_phone"`
	OpenOrderCode      int64  `json:"open_order_code"`
	PlatformCode       string `json:"platform_code"`
	ErrorScene         string `json:"error_scene"`
	Description        string `json:"description"`
	ErrorCode          string `json:"error_code"`
	DetailDescription  string `json:"detail_description"`
}

func (a *API) GetOrderCallbackMsg(data []byte) (orderMsg *WayBillInfo) {
	callbackInfo := &CallBackInfo{}
	err := utils.UnmarshalUseNumber(data, callbackInfo)
	if err != nil {
		globals.SugarLogger.Debugf("fn msg faild %v, err : %v", string(data), err)
		return nil
	}
	if err == nil {
		if str, err := url.QueryUnescape(callbackInfo.Data); err == nil {
			orderMsg = &WayBillInfo{}
			if err := utils.UnmarshalUseNumber([]byte(str), orderMsg); err == nil {
				return orderMsg
			} else {
				globals.SugarLogger.Debugf("fn msg faild3 %v", err)
				return nil
			}
		} else {
			globals.SugarLogger.Debugf("fn msg faild2 %v", err)
			return nil
		}
	}
	return orderMsg
}
