package com.gh.gamecenter.entity

import android.os.Parcelable
import com.gh.common.constant.Config
import com.gh.gamecenter.common.entity.LinkEntity
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize

@Parcelize
class GameDetailEntity(
    var id: String? = null,

    var info: TipsEntity? = null,

    @SerializedName("top_tag")
    var topTag: ArrayList<TagEntity>? = null,

    @SerializedName("update_des")
    var updateDes: String? = "",

    var video: ArrayList<String>? = arrayListOf(),

    @SerializedName("image_recommend")
    var imageRecommend: LinkEntity? = null,

    private var tag: ArrayList<TagEntity>? = null,

    private var tips: TipsEntity? = null,

    var news: List<NewsEntity>? = null,

    var gallery: ArrayList<String>? = null,

    var des: String? = null,

    @SerializedName("article_types")
    var articleTypes: ArrayList<String>? = null,

    @SerializedName("share_code")
    var shareCode: String? = null,

    @SerializedName("download_off_text")
    var downloadOffText: String? = null,

    @SerializedName("skin_test")
    var isSkinTest: Boolean = false,

    var contact: GameDetailContact? = null,

    var notice: MutableList<NewsEntity>? = null,

    @SerializedName("tag_style")
    var tagStyle: ArrayList<TagStyleEntity> = ArrayList(),

    @SerializedName("server")
    var serverEntity: GameDetailServer? = null,

    @SerializedName("related_game")
    var relatedGames: List<GameDetailRelatedGame>? = null,

    var fulishuoming: String? = null,

    @SerializedName("show_comment")
    val showComment: Boolean = false,

    @SerializedName("me")
    var me: MeEntity = MeEntity(),

    @SerializedName("related_version")
    var relatedVersion: ArrayList<RelatedVersion> = arrayListOf(),

    @SerializedName("custom_columns")
    var customColumns: ArrayList<CustomColumn> = arrayListOf(),

    @SerializedName("detail_dialog")
    var detailDialog: GameEntity.Dialog? = null,

    @SerializedName("server_label")
    val serverLabel: ColorEntity? = null,

    @SerializedName("top_video")
    var topVideo: Video? = null,

    @SerializedName("intro_video")
    var introVideo: Video? = null,

    @SerializedName("direct_comment")
    val directComment: Boolean = false
) : Parcelable {

    fun getTag(): ArrayList<TagEntity> {
        if (!Config.isShowPlugin(id)) return ArrayList()
        return tag!!
    }

    fun setTag(tag: ArrayList<TagEntity>) {
        this.tag = tag
    }

    fun getTips(): TipsEntity? {
        if (!Config.isShowPlugin(id)) return null
        return tips!!
    }

    fun setTips(tips: TipsEntity) {
        this.tips = tips
    }


    companion object {
        const val TAG: String = "GameDetailEntity"
    }

    @Parcelize
    data class Video(
        @SerializedName("_id", alternate = ["video_id"])
        var videoId: String = "",
        @SerializedName(
            "new_video_count",
            alternate = ["video_count"]
        ) // 选用 JSON 最后一个值作为 videoCount 的值
        var videoCount: Int = 0,
        var poster: String = "",
        var title: String = "",
        var url: String = "",
        var user: User? = null,
        var vote: Int = 0
    ) : Parcelable

    @Parcelize
    data class RelatedVersion(
        var first: Boolean = false,
        var last: Boolean = false,
        var game: SimpleGame? = null,
        @SerializedName("game_id")
        var gameId: String = "",
        @SerializedName("game_name")
        private var mGameName: String = "",
        @SerializedName("name_suffix")
        var nameSuffix: String? = "",
        @SerializedName("game_icon")
        var gameIcon: String = "",
        @SerializedName(value = "game_tag", alternate = arrayOf("new_game_tag"))
        var gameTags: ArrayList<TagStyleEntity> = ArrayList(),
        var index: Int
    ) : Parcelable {
        @IgnoredOnParcel
        val gameName: String
            get() = mGameName.removeSuffix(".") + (nameSuffix ?: "")
    }

    @Parcelize
    data class CustomColumn(
        var name: String,
        var link: LinkEntity? = null,
        @SerializedName("info_tag")
        var infoTag: ArrayList<TagEntity> = arrayListOf(),
        var title: Title? = null,
        var order: Int = 0,
        var des: String = "",
        @SerializedName("show_info_tag_des")
        var showInfoTagDes: Boolean = true,
        @SerializedName("show_info_tag")
        var showInfoTag: Boolean = true
    ) : Parcelable {

        @Parcelize
        data class Title(var icon: String, var value: String, var color: String) : Parcelable {
            fun titleToTips(des: String): TipsEntity {
                return TipsEntity(
                    icon = icon,
                    content = des,
                    title = TitleEntity(color = color, value = value)
                )
            }
        }

    }
}
