package com.gh.gamecenter.entity

import android.os.Parcelable
import com.gh.gamecenter.feature.entity.GameSubjectData
import com.gh.gamecenter.home.custom.model.CustomPageItem
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize

@Parcelize
data class SubjectData(
    // 入口必填
    var subjectId: String?,
    var subjectName: String?,
    var isOrder: Boolean?,
    // 专题内参数
    var sort: String = "", // Filter:评分/最新/最热/更新
    var filter: String = "", // Filter: 类型(分类)
    var tagType: String? = "", // 游戏Item 标签类型
    var briefStyle: String = "",
    var subjectType: SubjectType = SubjectType.NORMAL,
    var subjectStyle: String = "",
    var showDetailSubtitle: Boolean = false,
    var showDetailIconSubscript: Boolean = false,
    var customLimit: String = "", // unlimited（无限制）、forbidden（禁止移出）

    var requireUpdateSetting: Boolean = false, // 多专题页面需要专题页面自行获取专题配置
    var isAdData: Boolean = false,
    var adId: String = "", // 广告ID(本地字段)，不为空时为广告专题
    var codeId: String = "", // 广告CODE_ID(本地字段)，不为空时为广告专题
    var tag: String = "" // 分类标签，埋点用
) : Parcelable, Cloneable {

    @IgnoredOnParcel
    val isForbidden
        get() = customLimit == "forbidden"

    @IgnoredOnParcel
    val sortChinese
        get() = when {
            sort.contains("publish") -> "最新"
            sort.contains("star") -> "评分"
            sort.contains("update") -> "更新"
            else -> "推荐"
        }

    @IgnoredOnParcel
    val subjectStyleChinese: String
        get() = CustomPageItem.subjectTypeToComponentStyle[subjectStyle] ?: ""

    fun deepCopy(): SubjectData {
        return super.clone() as SubjectData
    }

    fun toGameSubjectData(): GameSubjectData {
        return GameSubjectData(
            id = subjectId,
            name = subjectName,
            isOrder = isOrder ?: false,
            briefStyle = briefStyle,
            tag = tagType
        )
    }

    /**
     * 专题类型
     */
    enum class SubjectType {
        /**
         * 普通专题
         */
        NORMAL,

        /**
         * QQ小游戏专题
         */
        QQ_GAME,

        /**
         * 微信小游戏专题
         */
        WECHAT_GAME,

        /**
         * 微信小游戏CPM专题
         */
        WECHAT_GAME_CPM,
    }
}
