package com.quyunshuo.module.home.getui

import android.content.Context
import android.util.Log
import com.google.gson.Gson
import com.igexin.sdk.GTIntentService
import com.igexin.sdk.message.GTCmdMessage
import com.igexin.sdk.message.GTNotificationMessage
import com.igexin.sdk.message.GTTransmitMessage
import com.quyunshuo.androidbaseframemvvm.common.constant.Heartbeat
import com.quyunshuo.module.home.name.PushName

class MyIntentService : GTIntentService() {
    override fun onReceiveServicePid(p0: Context?, p1: Int) {
    }

    override fun onReceiveClientId(p0: Context?, clientid: String?) {
        Log.d(TAG, "onReceiveClientId -> clientid = $clientid")
        Heartbeat.clientId = clientid
    }

    override fun onReceiveMessageData(context: Context?, gtTransmitMessage: GTTransmitMessage?) {


// 透传消息的处理，详看SDK demo
        val appid = gtTransmitMessage!!.appid
        val taskid = gtTransmitMessage!!.taskId
        val messageid = gtTransmitMessage!!.messageId
        val payload = gtTransmitMessage!!.payload
        val pkg = gtTransmitMessage!!.pkgName
        val cid = gtTransmitMessage!!.clientId
        val data = String(payload)
        val gson = Gson()
        Log.e(TAG, "onReceiveMessageData: data:$data")
        val realData = data
        Log.e(TAG, "onReceiveMessageData : realData=$realData")
        val baseBean: BaseBean = gson.fromJson(realData, BaseBean::class.java)
        val kind: String = baseBean.kind
        when (kind) {
            PushName.STATUS_TYPE -> {
                statusType(gson, baseBean, kind)

            }

            else -> {}
        }

    }

    override fun onReceiveOnlineState(p0: Context?, p1: Boolean) {
    }

    override fun onReceiveCommandResult(p0: Context?, p1: GTCmdMessage?) {
    }

    override fun onNotificationMessageArrived(p0: Context?, p1: GTNotificationMessage?) {
    }

    override fun onNotificationMessageClicked(p0: Context?, p1: GTNotificationMessage?) {
    }

    /**
     * 初始化回调
     */
    fun statusType(gosn: Gson, baseBean: BaseBean, kind: String) {

    }
}