package mtwmapi

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

type DistributeOrderDetail struct {
	WmOrderID              int         `json:"wm_order_id"`
	WmPoiID                int         `json:"wm_poi_id"`
	LogisticsStatus        int         `json:"logistics_status"`
	LogisticsCode          string      `json:"logistics_code"`
	LogisticsID            int         `json:"logistics_id"`
	LogisticsName          string      `json:"logistics_name"`
	PoiShippingFee         float64     `json:"poi_shipping_fee"`
	TipAmount              float64     `json:"tip_amount"`
	SelfDispatch           int         `json:"self_dispatch"`
	DispatchCancelAllow    int         `json:"dispatch_cancel_allow"`
	DispatcherName         string      `json:"dispatcher_name"`
	DispatcherPhone        interface{} `json:"dispatcher_phone"`
	OrgLeaderPhone         interface{} `json:"org_leader_phone"`
	OrgEmergencyPhone      interface{} `json:"org_emergency_phone"`
	LatestDeliveryTime     int         `json:"latest_delivery_time"`
	WaitingTime            int         `json:"waiting_time"`
	IsThirdPartShipping    int         `json:"is_third_part_shipping"`
	ThirdPartShippingName  interface{} `json:"third_part_shipping_name"`
	ThirdPartShippingPhone interface{} `json:"third_part_shipping_phone"`
	IsKS                   int         `json:"isKS"`
	DispatchTeam           interface{} `json:"dispatchTeam"`
	HhKS                   bool        `json:"hhKS"`
	PreCheckJuHeMsg        interface{} `json:"preCheckJuHeMsg"`
	HasJuheAndZB           bool        `json:"hasJuheAndZB"`
	PtGray                 int         `json:"ptGray"`
	ShippingFeeDetailVo    interface{} `json:"shippingFeeDetailVo"`
	AssignTime             int         `json:"assignTime"`
	AssignDegrade          bool        `json:"assignDegrade"`
	CurrentTime            int         `json:"currentTime"`
	SubLogisticsCode       int         `json:"subLogisticsCode"`
	DelayPushSecond        int         `json:"delay_push_second"`
}

//美团骑手修改小费，单位为元，最多小数点后一位
//order/receive/processed/w/distribute/tipAmount/v2?ignoreSetRouterProxy=true
func (a *API) OrderModityTips(orderID, poiCode string, tipAmount float64) (err error) {
	params := map[string]interface{}{
		"wmOrderViewId": orderID,
		"wmPoiId":       poiCode,
		"tipAmount":     tipAmount,
	}
	_, err = a.AccessUserPage2("v2/order/receive/processed/w/distribute/tipAmount/v2", params, true)
	return err
}

//获取美团订单小费
//https://shangoue.meituan.com/v2/order/receive/processed/r/distribute/list/v2
func (a *API) GetDistributeOrderDetail(orderID, poiCode string) (distributeOrderDetail *DistributeOrderDetail, err error) {
	params1 := map[string]interface{}{
		"wmOrderViewId": orderID,
		"wmPoiId":       poiCode,
	}
	params := map[string]interface{}{
		"orderInfos": []string{string(utils.MustMarshal(params1))},
	}
	result, err2 := a.AccessUserPage2("v2/order/receive/processed/r/distribute/list/v2", params, false)
	if err2 != nil {
		return distributeOrderDetail, err
	}
	err = utils.Map2StructByJson(result[orderID], &distributeOrderDetail, true)
	return distributeOrderDetail, err
}
