package com.adealink.weparty.push.data

import android.text.Spannable
import com.adealink.frame.push.data.KEY_PUSH_DEEPLINK
import com.adealink.frame.push.data.KEY_PUSH_ID
import com.adealink.frame.push.data.KEY_PUSH_MESSAGE
import com.adealink.frame.push.data.KEY_PUSH_MESSAGE_TYPE
import com.adealink.frame.push.data.KEY_PUSH_TITLE
import com.adealink.frame.push.data.PushMessage
import com.adealink.weparty.module.profile.data.UserInfo
import com.google.gson.annotations.GsonNullable
import com.google.gson.annotations.SerializedName

enum class PushMessageType(val type: Long) {
    UPLOAD_USER_LOG(-2), //上传用户日志
    ACTIVITY(5), //自建活动
    IM(40), //1v1会话提示
    SEND_GIFT(41), //送礼提示
    INTIMACY_ONLINE(44), //亲密度上线提醒
    INCOME_IM(45), //1v1付费消息
    CALL_MATCH_ASK(58), //匹配邀请
    CALL_MATCH_RESULT(62), //匹配结果通知
}

/**
 * 端内通知条消息
 */
data class NotificationMessage(
    @SerializedName(KEY_PUSH_ID)
    val pushId: Long,
    @SerializedName(KEY_PUSH_MESSAGE_TYPE)
    val messageType: Long,
    @GsonNullable
    @SerializedName(KEY_PUSH_TITLE)
    val title: String?,
    @GsonNullable
    @SerializedName(KEY_PUSH_MESSAGE)
    val message: String?,
    @GsonNullable
    @SerializedName(KEY_TARGET_ID)
    val targetId: String?,
    @GsonNullable
    @SerializedName(KEY_LARGE_ICON_URL)
    var largeIconUrl: String?,
    @GsonNullable
    @SerializedName(KEY_PUSH_DEEPLINK)
    val deeplink: String?,
) {
    @GsonNullable
    var messageSummary: Spannable? = null
    @GsonNullable
    var btnText: String? = null
    @GsonNullable
    var targetUserInfo: UserInfo? = null
    @GsonNullable
    var messageId: Int? = null

    fun toPushMessage(): PushMessage {
        val paramMap = hashMapOf(
            KEY_TARGET_ID to (targetId ?: ""),
            KEY_LARGE_ICON_URL to (largeIconUrl ?: ""),
            KEY_MESSAGE_ID to (messageId?.toString() ?: "")
        )
        return PushMessage(pushId, messageType, title, message, btnText, deeplink, paramMap)
    }
}

class JiehePushMessage(pushMessage: PushMessage, val channelId: String) {
    var pushId: Long = pushMessage.pushId
    var messageType: Long = pushMessage.messageType
    var pushTitle: String? = null
    var pushContent: String? = null
    var deeplink: String? = null
    var paramMap: Map<String, String>? = null

    init {
        pushTitle = pushMessage.pushTitle
        pushContent = pushMessage.pushContent
        deeplink = pushMessage.deeplink
        paramMap = pushMessage.paramMap
    }

    fun getLargeIconUrl(): String? {
        return paramMap?.get(KEY_LARGE_ICON_URL)
    }

    fun getTargetId(): String? {
        return paramMap?.get(KEY_TARGET_ID)
    }

    fun getMessageId(): String? {
        return paramMap?.get(KEY_MESSAGE_ID)
    }
}