package com.gh.gamecenter.common.entity

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

class ErrorEntity(
    var code: Int? = 0,
    var detail: String? = "",
    var toast: String? = "",
    var data: Data? = null
) {
    class Data(
        @SerializedName("always_block")
        var alwaysBlock: Boolean? = false,
        @SerializedName("game_id")
        var gameId: String = "",
        @SerializedName("game_name")
        var gameName: String = "",
        var nickname: String = "",

        // post question
        @SerializedName("question_id")
        var questionId: String = "",
        @SerializedName("question_title")
        var questionTitle: String = "",
        @SerializedName("answer_count")
        var answerCount: Int = 0,
        @SerializedName("follow_count")
        private var followCount: Int = 0,
        val content: String = "",
        val title: String = "",
        val type: String = "",
        val link: String = "",
        val text: String = "",
        @SerializedName("link_community", alternate = ["community"])
        var community: CommunityEntity? = CommunityEntity(),
        @SerializedName("bind")
        private val _bind: Boolean? = null,
        @SerializedName("user_conflict")
        private val _userConflict: UserConflict? = null
    ) {
        // 问题关注数默认是1
        fun getFollowCount(): Int {
            if (followCount > 0) return followCount
            return 1
        }

        fun toLinkEntity(): LinkEntity {
            return LinkEntity(
                title = title,
                link = link,
                type = type,
                text = text,
                community = community
            )
        }

        val userConflict: UserConflict
            get() = _userConflict ?: UserConflict()

        @Parcelize
        data class UserConflict(
            @SerializedName("_id")
            private val _id: String? = null,
            @SerializedName("name")
            private val _name: String? = null,
            @SerializedName("icon")
            private val _icon: String? = null,
            @SerializedName("_seq")
            private val _seq: String? = null
        ) : Parcelable {

            val id: String
                get() = _id ?: ""

            val name: String
                get() = _name ?: ""

            val icon: String
                get() = _icon ?: ""

            val seq: String
                get() = _seq ?: ""
        }
    }
}