package com.gh.gamecenter.common.entity

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

@Parcelize
data class CommunityEntity(
    @SerializedName("_id", alternate = ["id"])
    var id: String = "",
    var name: String = "",
    var refreshSort: String = "choiceness", // choiceness/time
    @SerializedName("icon", alternate = ["ori_icon"])
    var icon: String? = "",
    @SerializedName("icon_subscript")
    var iconSubscript: String? = null,
    var type: String = "game_bbs",//game_bbs/official_bbs
    var game: CommunityGameEntity? = null
) : Parcelable {
    constructor(id: String = "", name: String = "") : this(id, name, "choiceness")

    val typeChinese: String get() = when (type) {
        "game_bbs" -> "游戏论坛"
        else -> "综合论坛"
    }

    @Parcelize
    class CommunityGameEntity(
        @SerializedName("_id")
        var id: String? = null,
        @SerializedName("name")
        var mName: String? = "",
        @SerializedName("icon")
        var mIcon: String? = null,
        @SerializedName("ori_icon")
        var mRawIcon: String? = null,
        @SerializedName("icon_subscript")
        var iconSubscript: String? = null,
        @SerializedName("icon_float")
        var iconFloat: IconFloat? = null,
        var category: String? = ""
    ) : Parcelable {

        @IgnoredOnParcel
        val name: String?
            get() = mName?.removeSuffix(".")

        fun getIcon(): String {
            return mRawIcon ?: mIcon ?: ""
        }

        @IgnoredOnParcel
        val categoryChinese: String
            get() = when (category) {
                "online" -> "网络"
                "local" -> "单机"
                "welfare" -> "福利"
                "simulator" -> "模拟器"
                else -> category ?: ""
            }
    }

    companion object {
        const val SORT_TIME = "time"
    }
}