package com.gh.gamecenter.entity

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.gh.gamecenter.R
import com.gh.gamecenter.qa.entity.Count
import com.gh.gamecenter.qa.entity.TimeEntity
import com.gh.gamecenter.room.converter.*
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

@Entity
@Parcelize
class GamesCollectionEntity(
    @PrimaryKey
    @SerializedName("_id")
    var id: String = "",
    @TypeConverters(TagInfoListConverter::class)
    var tags: ArrayList<TagInfoEntity>? = null,
    @TypeConverters(ActivityLabelListConverter::class)
    @SerializedName("activity_tags")
    var activityTags: ArrayList<ActivityLabelEntity>? = null,
    @TypeConverters(SimpleGameListConverter::class)
    var games: ArrayList<SimpleGame>? = null,
    var title: String = "",
    var intro: String = "",
    var cover: String = "",
    var display: String = "",//self_only: 仅自己可见
    var stamp: String = "",//special_choice: 精选 offical: 官方
    @TypeConverters(CountConverter::class)
    var count: Count? = null,
    @TypeConverters(UserConverter::class)
    var user: User? = null,
    @TypeConverters(MeConverter::class)
    var me: MeEntity? = null,
    var orderTag: Long = 0,
    @Ignore
    var time: TimeEntity? = null,
    @Ignore
    var status: String = "",// draft/pending/pass/failed
    @Ignore
    @SerializedName("ad_icon_active")
    var adIconActive: Boolean = false,
    //本地字段
    @Ignore
    var isLocalDraft: Boolean = false
) : Parcelable {

    fun getStatusLabelRes(): Int {
        return when {
            display == "self_only" && status == "pass" -> R.drawable.ic_game_collection_private
            status == "draft" -> R.drawable.ic_game_collection_draft
            status == "pending" -> R.drawable.ic_game_collection_pending
            status == "failed" -> R.drawable.ic_game_collection_fail
            else -> -1
        }
    }

    fun getTagIds(): String {
        val sb = StringBuffer()
        tags?.forEach {
            sb.append(it.id)
        }
        return sb.toString()
    }
}
