package com.casic.br.service

import android.content.Context
import android.util.Log
import com.casic.br.fragment.MessagePageFragment
import com.casic.br.utils.LocaleConstant
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.pengxh.kt.lite.extensions.toJson
import com.pengxh.kt.lite.utils.SaveKeyValues

class PushIntentService : GTIntentService() {

    private val kTag = "PushIntentService"

    override fun onReceiveServicePid(context: Context?, pid: Int) {

    }

    // 透传消息
    override fun onReceiveMessageData(context: Context?, msg: GTTransmitMessage?) {
        Log.d(kTag, "透传消息 -> msg = $msg")
    }

    // 接收 cid
    override fun onReceiveClientId(context: Context?, clientid: String?) {
        Log.d(kTag, "onReceiveClientId -> $clientid")
        SaveKeyValues.putValue(LocaleConstant.PUSH_CLIENT_ID, clientid.toString())
    }

    // cid 离线上线通知
    override fun onReceiveOnlineState(context: Context?, online: Boolean) {

    }

    // 各种事件处理回执
    override fun onReceiveCommandResult(context: Context?, msg: GTCmdMessage?) {

    }

    // 通知到达
    override fun onNotificationMessageArrived(context: Context?, msg: GTNotificationMessage?) {
        if (msg == null) {
            return
        }
        Log.d(kTag, "通知到达 -> msg = ${msg.toJson()}")
        MessagePageFragment.weakReferenceHandler.sendEmptyMessage(2022101002)
    }

    // 通知点击
    override fun onNotificationMessageClicked(context: Context?, msg: GTNotificationMessage?) {
        Log.d(kTag, "通知点击 -> msg = $msg")
    }
}