package ebai

import (
	"encoding/json"

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

	"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
	"git.rosy.net.cn/jx-callback/business/partner/im"
	"git.rosy.net.cn/jx-callback/globals/api"
)

const (
	IMVendorIDELM = 3 //饿了么
)

// OnImMessage 用户/骑手 发送/已读消息 回调
func (p *PurchaseHandler) OnImMessage(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse) {
	globals.SugarLogger.Debugf("ebaiOnImMessage msg=%s", utils.Format4Output(msg, false))
	str, err := json.Marshal(msg.Data)

	err = im.ReadMsgFromVendor(IMVendorIDELM, msg.Source, str)
	if err != nil {
		return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, msg.Cmd)
	}
	return nil
}

// BusinessSendMsg 向门店发送消息
//func BusinessSendMsg(param *ebaiapi.BusinessSendMsgReq) error {
//	err := api.EbaiAPI.BusinessSendMsg(param)
//	return err
//}

// GetStoreIMStatus 查询门店IM开关状态
//func GetStoreIMStatus(platformShopId string) (string, error) {
//	retVal, err := api.EbaiAPI.GetStoreIMStatus(platformShopId)
//	return retVal, err
//}

// UpdateIMStatus 更新店铺IM开关状态 1-开启,-1-关闭
//func UpdateIMStatus(platformShopId string, status int) error {
//	err := api.EbaiAPI.UpdateIMStatus(platformShopId, status)
//	return err
//}
