package com.gh.gamecenter.personalhome.rating

import androidx.annotation.Keep
import com.gh.gamecenter.entity.*
import com.google.gson.annotations.SerializedName
import java.text.SimpleDateFormat
import java.util.*

/**
 * 该实体与View同级,因为其他页面也用不着
 */
@Keep
data class MyRating(
    @SerializedName("_id")
    val id: String = "",
    var star: Int = 0,
    var content: String = "",
    val time: Long = 0,
    var vote: Int = -1,
    var reply: Int = -1,
    var user: PersonalEntity? = null,
    var me: MeEntity = MeEntity(),
    val active: Boolean = true,
    var audit: Boolean = false,
    @SerializedName("is_jingxuan")
    val excellent: Boolean = false,
    @SerializedName("anliwall")
    val amway: Boolean = false,
    val game: PersonalHistoryEntity.Game = PersonalHistoryEntity.Game()
) {

    fun transformHistoryEntity(): PersonalHistoryEntity {
        return PersonalHistoryEntity(
            id = id,
            time = time,
            comment = PersonalHistoryEntity.Comment(
                id = id,
                star = star,
                content = content,
                game = game
            ),
            count = PersonalHistoryEntity.Count(vote = vote, reply = reply),
            user = user
        )
    }

    fun getFormatTime(pattern: String): String? {
        if (time == 0L) return null
        val formatTime = SimpleDateFormat(pattern, Locale.CHINA)
        return formatTime.format(time * 1000)
    }

    fun transformGameEntity(): GameEntity {
        return GameEntity(
            id = game.id,
            mName = game.name,
            nameSuffix = game.nameSuffix,
            mIcon = game.icon,
            mTagStyle = game.tag,
            star = game.star
        )
    }

    fun transformCommentEntity(): RatingComment {
        return RatingComment(
            id = id, content = content, star = star, vote = vote, reply = reply, time = time,
            me = me, active = active, audit = audit,
            user = UserEntity(id = user?.id, name = user?.name, icon = user?.icon)
        )
    }
}