package com.gh.gamecenter.feature.entity

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

@Parcelize
data class PersonalEntity(
    @SerializedName("_id")
    val id: String = "",
    @SerializedName("_seq")
    private val shortUserId: Long = 0L, // 短用户ID，用于前端展示
    var name: String = "",
    var icon: String = "",
    var introduce: String? = "",
    @SerializedName("name_label")
    var nameLabel: String? = "",
    val count: Count = Count(),
    val auth: Auth? = null,
    val badge: Badge? = null,
    val me: MeEntity = MeEntity(),
    @SerializedName("icon_border_url")
    var border: String = "",
    @SerializedName("icon_border")
    var iconBorder: AvatarBorderEntity? = null,
    var background: BackgroundImageEntity? = null,
    @SerializedName("last_visitor")
    val lastVisitor: LastVisitor? = null,
    @SerializedName("etiquette_exam")
    val regulationTest: RegulationTest? = null,
    val source: SourceEntity? = null,
    @SerializedName("mobile_auth")
    var mobileAuth: MobileAuthEntity? = null
) : Parcelable {
    @Parcelize
    class Count(
        // 包括回答点赞和社区文章点赞
        val vote: Int? = 0,
        var answer: Int = 0,
        var question: Int = 0,
        var fans: Int = 0,
        val follower: Int = 0,
        @SerializedName("community_article")
        var communityArticle: Int = 0,
        @SerializedName("game_comment")
        val gameComment: Int = 0,
        var video: Int = 0,
        @SerializedName("game_list")
        val gameList: Int = 0,
        @SerializedName("today_visit")
        val todayVisit: Int? = 0
    ) : Parcelable {

        fun getTotalCount() = video + answer + question + communityArticle
    }

    fun getShortUserId(): String {
        return if (shortUserId.toString().length < 8) {
            String.format("%08d", shortUserId)
        } else {
            shortUserId.toString()
        }
    }
}

// 礼仪测试
@Parcelize
class RegulationTest(
    var status: String = "",
    var rank: Int = 0
) : Parcelable

// 最近访客
@Parcelize
class LastVisitor(
    @SerializedName("_id")
    var id: String = "",
    var name: String = "",
    var icon: String = ""
) : Parcelable

// 徽章
@Parcelize
class Badge(
    var name: String = "",
    @SerializedName(value = "icon")
    var mIcon: String = "",
    @SerializedName(value = "small_icon")
    var smallIcon: String = "",
    var actions: List<BadgeAction>? = null
) : Parcelable {
    @IgnoredOnParcel
    val icon: String
        get() = smallIcon.ifEmpty { mIcon }
}

// 徽章领取条件
@Parcelize
class BadgeAction(
    var text: String = "",
    @SerializedName("_id")
    var id: String = "",
    var name: String = "",
    var icon: String = ""
) : Parcelable

