package com.gh.gamecenter.jg.push.service

import android.content.Context
import cn.jpush.android.api.NotificationMessage
import cn.jpush.android.service.JPushMessageReceiver
import com.gh.gamecenter.jg.push.JPushHelper
import com.lightgame.utils.Utils

class HaloJPushMessageReceiver: JPushMessageReceiver() {
    override fun onRegister(context: Context?, registrationId: String?) {
        Utils.log(TAG, "onRegister: $registrationId")
        JPushHelper.bindRegistrationId(registrationId)
    }

    override fun onNotifyMessageArrived(context: Context, message: NotificationMessage) {
        super.onNotifyMessageArrived(context, message)
        Utils.log(TAG, "onNotifyMessageArrived: $message")

        JPushHelper.appendBadgeNumber(context.applicationContext)
    }

    override fun onNotifyMessageOpened(context: Context, message: NotificationMessage) {
        super.onNotifyMessageOpened(context, message)
        Utils.log(TAG, "onNotifyMessageOpened: $message")

        JPushHelper.subtractBadgeNumber(context.applicationContext)
        JPushHelper.onNotifyMessageOpened(
            message.msgId ?: "",
            message.notificationTitle ?: "",
            message.notificationContent ?: "",
            message.deeplink ?: ""
        )
    }

    override fun onNotifyMessageDismiss(context: Context, message: NotificationMessage) {
        super.onNotifyMessageDismiss(context, message)
        Utils.log(TAG, "onNotifyMessageDismiss: $message")

        JPushHelper.subtractBadgeNumber(context.applicationContext)
    }

    companion object {
        const val TAG = "HaloJPushMessageReceiver"
    }
}