package com.gh.gamecenter.entity

import com.gh.gamecenter.common.utils.tryWithDefaultCatch
import com.gh.gamecenter.feature.entity.UserEntity
import com.google.gson.annotations.SerializedName
import java.util.*

/**
 * Created by khy on 2017/4/12.
 * 消息未读数据实体
 */
class MessageUnreadEntity {

    var invited: Int = 0

    @SerializedName("answer_vote")
    var answerVote: Int = 0

    @SerializedName("comment_vote")
    var commentVote: Int = 0

    @SerializedName("answer_comment_vote")
    var answerCommentVote: Int = 0

    var service: Int = 0

    var total: Int = 0

    var answer: Int = 0

    var reply: Int = 0

    @SerializedName("follow_question")
    var followQuestion: Int = 0

    @SerializedName("reply_answer_comment")
    var replyAnswerComment: Int = 0

    @SerializedName("answer_comment")
    var answerComment: Int = 0

    @SerializedName("system_invited")
    var systemInvited: Int = 0

    @SerializedName("community_article_vote")
    var communityArticleVote: Int = 0

    @SerializedName("community_article_comment_vote")
    var communityArticleCommentVote: Int = 0

    @SerializedName("community_article_comment")
    var communityArticleComment: Int = 0

    @SerializedName("reply_community_article_comment")
    var replyCommunityArticleComment = 0

    @SerializedName("video_vote")
    var videoVote = 0

    @SerializedName("video_comment_vote")
    var videoCommentVote = 0

    @SerializedName("game_comment_vote")
    var gameCommentVote = 0

    @SerializedName("game_comment_reply_vote")
    var gameCommentReplyVote = 0

    @SerializedName("activity_comment")
    var activityComment = 0

    @SerializedName("reply_activity_comment")
    var replyActivityComment = 0

    @SerializedName("activity_comment_vote")
    var activityCommentVote = 0

    @SerializedName("activity_comment_reply_vote")
    var activityCommentReplyVote = 0

    @SerializedName("game_list_comment")
    var gameListComment = 0

    @SerializedName("game_list_comment_reply")
    var gameListCommentReply = 0

    @SerializedName("game_list_comment_vote")
    var gameListCommentVote = 0

    @SerializedName("game_list_vote")
    var gameListVote = 0

    @SerializedName("community_article_comment_reply_vote")
    var communityArticleCommentReplyVote = 0

    @SerializedName("game_comment_reply")
    var gameCommentReply = 0

    @SerializedName("video_comment")
    var videoComment = 0

    @SerializedName("video_comment_reply")
    var videoCommentReply = 0

    @SerializedName("video_comment_reply_vote")
    var videoCommentReplyVote = 0

    var fans: Int = 0 // 与其他未读区分 用于我的主页

    var meta: Meta? = null

    class Meta(
        @SerializedName("message_id")
        var messageId: String? = "",
        @SerializedName("answer_id")
        var answerId: String? = "",
        var type: String? = "",
        var user: UserEntity? = null
    )

    // 遍历含 vote 的成员变量，累加点赞数
    fun getVoteCount(): Int {
        var voteCount = 0

        tryWithDefaultCatch {
            val fields = this.javaClass.declaredFields
            for (field in fields) {
                if (field.name.toLowerCase(Locale.getDefault()).contains("vote") && field.type == Integer.TYPE) {
                    voteCount += field.getInt(this)
                }
            }
        }
        return voteCount
    }

    // 归零所有名字含 vote 的成员变量
    fun resetVote() {
        val fields = this.javaClass.declaredFields

        tryWithDefaultCatch {
            for (field in fields) {
                if (field.name.toLowerCase(Locale.getDefault()).contains("vote") && field.type == Integer.TYPE) {
                    field.setInt(this, 0)
                }
            }
        }
    }

}
