package com.gh.gamecenter.entity

import android.os.Parcelable
import androidx.annotation.DrawableRes
import com.gh.common.util.ViewPagerFragmentHelper
import com.gh.gamecenter.common.entity.LinkEntity
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

@Parcelize
data class BottomTab(
    @SerializedName("_id")
    val id: String = "",
    val name: String = "",
    @SerializedName("icon_select")
    val iconSelect: String = "", // 选中图片
    @SerializedName("icon_unselect")
    val iconUnselect: String = "", // 未选中图片
    @DrawableRes
    val iconSelector: Int = 0, // 本地字段
    @SerializedName("js_code")
    var jsCode: String = "", // js代码
    val link: LinkEntity? = null, // 通用链接
    @SerializedName("search_style")
    val searchStyle: SearchStyle = SearchStyle(), // 搜索样式
    @SerializedName("is_default_page")
    var default: Boolean = false, // 是否为默认显示页
    var guide: Guide? = null, // 引导文案
    var diverter: DiverterEntity? = null, // 分流器
    var isTransparentStyle: Boolean = false, // 本地字段，透明底部Tab
) : Parcelable {
    @Parcelize
    data class SearchStyle(
        @SerializedName("style_type")
        var styleType: String = STYLE_TWO_LINES, // 样式类型（two_lines：搜索栏与顶部tab分为两行、apposition：搜索栏与顶部tab同一行）
        @SerializedName("search_type")
        var searchType: String = TYPE_HALO_GAME, // 搜索类型（halo_game：光环游戏、bbs：论坛、mini_game：小游戏搜索（低于v5.36版本返回qq_mini_game））
    ) : Parcelable {
        companion object {
            const val STYLE_TWO_LINES = "two_lines"
            const val STYLE_APPOSITION = "apposition"
            const val TYPE_HALO_GAME = "halo_game"
            const val TYPE_MINI_GAME = "mini_game"
            const val TYPE_BBS = "bbs"
        }
    }

    @Parcelize
    data class Guide(
        var bottomTabId: String = "", // 底部tab id
        var multiTabId: String = "", // 多tab导航页id
        var text: String = "",
    ): Parcelable

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as BottomTab
        // 只对比链接类型和id、搜索样式判断是否相同
        if (link?.type != other.link?.type) return false
        if (link?.link == other.link?.link) return false
        return searchStyle == other.searchStyle
    }

    override fun hashCode(): Int {
        var result = link?.type?.hashCode() ?: 0
        result = 31 * result + (link?.link?.hashCode() ?: 0)
        result = 31 * result + searchStyle.hashCode()
        // 除我的光环页面外，增加计算底部tab id的HashCode
        if (link?.type != ViewPagerFragmentHelper.TYPE_MY_HALO) {
            result = 31 * result + id.hashCode()
        }
        return result
    }
}