package com.gh.gamecenter.entity

import android.os.Parcelable
import androidx.annotation.Keep
import androidx.room.Entity
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.feature.entity.GameEntity
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize


/**
 * @author : liujiarui
 * date : 2023/3/3
 * description : 首页-推荐tab-新游开测 item 实体类
 */
@Keep
@Entity
@Parcelize
data class HomeItemTestV2Entity(
    @SerializedName("action")
    val action: String = "",
    @SerializedName("count")
    val count: Int = 0,
    @SerializedName("limit")
    val limit: Int = 0,
    @SerializedName("page_id")
    val pageId: String = "",
    @SerializedName("recommend_label")
    val recommendLabel: List<RecommendLabel> = listOf(),
    @SerializedName("right_top")
    val rightTop: RightTop = RightTop(),
    @SerializedName("start_id")
    val startId: String = "",
    @SerializedName("recommend_data_point")
    private val _startPoint: Map<String, String> = mapOf(), // key 时间轴名称，value 当前时间轴第一个游戏id
    @SerializedName("recommend_data_count")
    private val _dataCount: Map<String, Int> = mapOf(), //key 时间轴名称，value 当前时间轴所包含的游戏数量
    @SerializedName("time_type")
    val timeType: String = "",
    @SerializedName("recommend_left_surplus_num") //首页推荐左侧剩余游戏数量
    val recommendLeftSurplusNum: Int = 0,
    // 首屏游戏列表
    val data: List<GameData> = emptyList(),
    // 用来判断是不是下拉刷新
    @Expose(serialize = false, deserialize = false)
    var isRefresh: Boolean = true
) : Parcelable {

    val dataCount: List<DataCount>
        get() {
            val dataCountList = arrayListOf<DataCount>()
            _dataCount.forEach { (key, value) ->
                dataCountList.add(DataCount(key, value))
            }
            return dataCountList
        }

    val startPoint: List<StartPoint>
        get() {
            val startPointList = arrayListOf<StartPoint>()
            _startPoint.forEach { (key, value) ->
                startPointList.add(StartPoint(key, value))
            }
            return startPointList
        }
}

@Keep
@Entity
@Parcelize
data class RecommendLabel(
    @SerializedName("_id")
    val id: String = "",
    @SerializedName("link")
    val link: LinkEntity = LinkEntity(),
    @SerializedName("text")
    val text: String = ""
) : Parcelable

@Keep
@Entity
@Parcelize
data class RightTop(
    @SerializedName("link")
    val link: LinkEntity = LinkEntity(),
    @SerializedName("text")
    val text: String = ""
) : Parcelable


@Keep
@Entity
@Parcelize
data class GameData(
    @SerializedName("start_midnight")
    val startMidnight: Long = 0L,
    @SerializedName("time_type")
    val timeType: String = "",//时间轴（recommend：推荐、xxxx-xx-xx：全部（比如：2023-01-01））
    var games: List<GameEntity> = emptyList()
) : Parcelable

/**
 * 新游开测游戏列表包装类
 */
@Keep
data class GameDataWrapper(
    var index: Int,
    val timeType: String = "",
    val gameData: GameEntity? = null,
    var isPlaceHolder: Boolean = false, //占位标识
    var isSpace: Boolean = false, //空条目标识
) {
    override fun toString(): String {
        return "（index = $index, " +
                "timeType = $timeType, " +
                "gameId = ${gameData?.id}, " +
                "gameName = ${gameData?.name}）"
    }
}

data class DataCount(
    val timeType: String,
    val count: Int
)

data class StartPoint(
    val timeType: String,
    val id: String
)
