package controllers

import (
	"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
	"git.rosy.net.cn/jx-callback/globals"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
)

type MtwmController struct {
	web.Controller
}

func (c *MtwmController) onCallbackMsg(msgType string) {
	c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
	msg, callbackResponse := api.MtwmAPI.GetCallbackMsg(c.Ctx.Request)
	globals.SugarLogger.Debug(utils.Format4Output(msg, true))
	if callbackResponse == nil {
		callbackResponse = mtwm.OnCallbackMsg(msg)
		if callbackResponse == nil {
			callbackResponse = mtwmapi.Err2CallbackResponse(nil, "")
		}
	}
	c.Data["json"] = callbackResponse
	c.ServeJSON()
}

func (c *MtwmController) WaybillStatus() {
	c.onCallbackMsg(mtwmapi.MsgTypeWaybillStatus)
}

func (c *MtwmController) NewOrder() {
	c.onCallbackMsg(mtwmapi.MsgTypeNewOrder)
}

func (c *MtwmController) OrderAccepted() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderAccepted)
}

func (c *MtwmController) OrderFinished() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderFinished)
}

func (c *MtwmController) OrderFinancial() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderFinancial)
}

func (c *MtwmController) UserUrgeOrder() {
	c.onCallbackMsg(mtwmapi.MsgTypeUserUrgeOrder)
}

func (c *MtwmController) NumberDowngrade() {
	c.onCallbackMsg(mtwmapi.MsgTypePrivateNumberDowngrade)
}

func (c *MtwmController) OrderModified() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderModified)
}

func (c *MtwmController) OrderCanceled() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderCanceled)
}

func (c *MtwmController) OrderRefund() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderRefund)
}

func (c *MtwmController) OrderPartialRefund() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderPartialRefund)
}

func (c *MtwmController) StoreStatusChanged() {
	c.onCallbackMsg(mtwmapi.MsgTypeStoreStatusChanged)
}

func (c *MtwmController) OrderFinishedPickup() {
	c.onCallbackMsg(mtwmapi.MsgTypeOrderFinishedPickup)
}

func (c *MtwmController) StoreAuditStatusChanged() {
	c.onCallbackMsg(mtwmapi.MsgTypeStoreAuditStatusChanged)
}

func (c *MtwmController) SkuDelete() {
	c.onCallbackMsg(mtwmapi.MsgTypeSkuDelete)
}

func (c *MtwmController) StoreBind() {
	c.onCallbackMsg(mtwmapi.MsgTypeStoreBind)
}
