package com.adealink.weparty.im.session.mesasge

import com.adealink.frame.data.json.froJsonErrorNull
import com.google.gson.annotations.SerializedName
import com.tencent.imsdk.v2.V2TIMMessage
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.TextReplyQuoteBean

data class OfficialImageTextData(
    @SerializedName("title") val title: String? = null, //标题
    @SerializedName("image") val image: String? = null, //配图
    @SerializedName("content") var content: String? = null, //正文
    @SerializedName("link") var link: String? = null, //链接
)

class OfficialImageTextMessageBean : TUIMessageBean() {

    var title: String? = null //标题
    var image: String? = null //配图
    var content: String? = null //正文
    var link: String? = null //链接
    override fun onGetDisplayString(): String? {
        return title
    }

    override fun onProcessMessage(v2TIMMessage: V2TIMMessage) {
        val byte = v2TIMMessage.customElem?.data ?: return
        val dataStr = String(byte)
        val messageData = froJsonErrorNull<OfficialImageTextData>(dataStr)
        //填充数据
        this.title = messageData?.title
        this.image = messageData?.image
        this.content = messageData?.content
        this.link = messageData?.link
    }

    override fun getReplyQuoteBeanClass(): Class<out TUIReplyQuoteBean<*>?> {
        return TextReplyQuoteBean::class.java
    }
}
