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")

    @Parcelize
    data class CommunityGameEntity(
        @SerializedName("_id")
        var id: String? = null,
        @SerializedName("name")
        var mName: String? = "",
        @SerializedName("name_suffix")
        var nameSuffix: String? = null,
        @SerializedName("icon")
        var mIcon: String? = null,
        @SerializedName("ori_icon")
        var mRawIcon: String? = null,
        @SerializedName("icon_subscript")
        var iconSubscript: String? = null
    ) : Parcelable {

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

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

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