package com.gh.gamecenter.gamedetail.entity

import android.os.Parcelable
import com.gh.gamecenter.common.entity.IconFloat
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.entity.PKEntity
import com.gh.gamecenter.entity.GameDetailRecommendGameCollectionEntity
import com.gh.gamecenter.entity.GameDetailRelatedGame
import com.gh.gamecenter.entity.RatingComment
import com.gh.gamecenter.entity.SubjectEntity
import com.gh.gamecenter.feature.entity.*
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize


data class GameDetailData(
    @SerializedName("_id")
    var id: String = "",
    var position: Int = -1, // 本地字段
    var type: String = "",
    val order: Order = Order(),
    @SerializedName("link_video_img_area")
    val linkVideoImgArea: List<CoverTabEntity>? = null,
    @SerializedName("link_basic_info")
    val linkBasicInfo: GameEntity? = null,
    @SerializedName("link_data_info")
    val linkDataInfo: List<GameDetailDataInfo>? = null,
    @SerializedName("link_info_tag")
    val linkInfoTag: GameDetailInfoTag? = null,
    @SerializedName("link_content_card")
    val linkContentCard: List<ContentCardEntity>? = null,
    @SerializedName("card_background")
    val cardBackground: CardBackground? = null,
    @SerializedName("link_advertising")
    val linkAdvertising: GameDetailLink? = null,
    @SerializedName("link_comprehensive")
    val linkComprehensive: GameDetailComprehensivePanelEntity? = null,
    @SerializedName("link_drawer")
    val linkDrawer: GameDetailLinksItem? = null,
    @SerializedName("link_announcement")
    val linkAnnouncement: GameDetailLinksItem? = null,
    @SerializedName("link_game_brief")
    val linkGameBrief: GameBrief? = null,
    @SerializedName("link_developer_word")
    val linkDeveloperWord: DeveloperWord? = null,
    @SerializedName("link_update")
    val linkUpdate: GameDetailUpdateContent? = null,
    @SerializedName("link_custom_column")
    val linkCustomColumn: GameDetailCustomColumn? = null,
    @SerializedName("link_comment")
    val linkComment: GameDetailComment? = null,
    @SerializedName("link_info")
    val linkInfo: GameDetailInfo? = null,
    @SerializedName("link_content_recommend")
    val linkContentRecommend: LinkEntity? = null,
    var pkData: PKEntity? = null,
    @SerializedName("link_game_video")
    val linkGameVideo: GameDetailVideo? = null,
    @SerializedName("link_game_guide")
    val linkGameGuide: GameDetailStrategy? = null,
    @SerializedName("link_server")
    val linkServer: GameDetailServer? = null,
    @SerializedName("link_libao")
    var linkLibao: ArrayList<LibaoEntity>? = null,
    @SerializedName("libao_count")
    var libaoCount: Int = 0,
    @SerializedName("link_related_game")
    val linkRelatedGame: ArrayList<GameEntity>? = null,
    @SerializedName("link_image_recommend")
    val linkImageRecommend: GameDetailRecommendImage? = null,
    @SerializedName("link_everyone_playing")
    val linkEveryonePlaying: GameDetailRecommendGame? = null,
    @SerializedName("link_recommend_game_list")
    val linkRecommendGameList: ArrayList<GameDetailRecommendGameCollectionEntity>? = null,
    @SerializedName("link_column_recommend")
    val linkColumnRecommend: List<GameDetailRecommendColumn>? = null,
    val recommendColumn: GameDetailRecommendColumn? = null,
) {
    val typeChinese
        get() = when (type) {
            TYPE_VIDEO_IMG_AREA -> "视频/图片区域"
            TYPE_BASIC_INFO -> "头部信息"
            TYPE_DATA_INFO -> "数据信息栏"
            TYPE_INFO_TAG -> "功能标签"
            TYPE_CONTENT_CARD -> "内容卡片"
            TYPE_ADVERTISING -> "广告推荐"
            TYPE_COMPREHENSIVE -> "综合面板"
            TYPE_CUSTOM_COLUMN -> "自定义栏目"
            TYPE_DRAWER -> "抽屉列表"
            TYPE_ANNOUNCEMENT -> "资讯公告"
            TYPE_GAME_BRIEF -> "游戏简介"
            TYPE_DEVELOPER_WORD -> "开发者的话"
            TYPE_UPDATE -> "更新内容"
            TYPE_COMMENT -> "玩家评论"
            TYPE_INFO -> "详情信息"
            TYPE_CONTENT_RECOMMEND -> "内容推荐（PK组件）"
            TYPE_GAME_VIDEO -> "游戏视频"
            TYPE_GAME_GUIDE -> "游戏攻略"
            TYPE_SERVER -> "游戏开服"
            TYPE_LIBAO -> "游戏礼包"
            TYPE_RELATED_GAME -> "相关游戏"
            TYPE_IMAGE_RECOMMEND -> "图片推荐"
            TYPE_EVERYONE_PLAYING -> "大家都在玩"
            TYPE_RECOMMEND_GAME_LIST -> "游戏单推荐"
            TYPE_COLUMN_RECOMMEND -> "专题推荐"
            else -> ""
        }

    fun areItemsTheSame(other: GameDetailData) = type == other.type
    fun areContentsTheSame(other: GameDetailData) = type == other.type && this == other

    companion object {
        const val TYPE_VIDEO_IMG_AREA = "video_img_area"
        const val TYPE_BASIC_INFO = "basic_info"
        const val TYPE_DATA_INFO = "data_info"
        const val TYPE_INFO_TAG = "info_tag"
        const val TYPE_CONTENT_CARD = "content_card"
        const val TYPE_ADVERTISING = "advertising"
        const val TYPE_COMPREHENSIVE = "comprehensive"
        const val TYPE_CUSTOM_COLUMN = "custom_column"
        const val TYPE_DRAWER = "drawer"
        const val TYPE_ANNOUNCEMENT = "announcement"
        const val TYPE_GAME_BRIEF = "game_brief"
        const val TYPE_DEVELOPER_WORD = "developer_word"
        const val TYPE_UPDATE = "update"
        const val TYPE_COMMENT = "comment"
        const val TYPE_INFO = "info"
        const val TYPE_CONTENT_RECOMMEND = "content_recommend"
        const val TYPE_GAME_VIDEO = "game_video"
        const val TYPE_GAME_GUIDE = "game_guide"
        const val TYPE_SERVER = "server"
        const val TYPE_LIBAO = "libao"
        const val TYPE_RELATED_GAME = "related_game"
        const val TYPE_IMAGE_RECOMMEND = "image_recommend"
        const val TYPE_EVERYONE_PLAYING = "everyone_playing"
        const val TYPE_RECOMMEND_GAME_LIST = "recommend_game_list"
        const val TYPE_COLUMN_RECOMMEND = "column_recommend"
    }
}

data class CardBackground(
    val color: String = "",
    val transparent: String = "",
    @SerializedName("color-transparent")
    val colorTransparent: String = "", // RGBA格式
)

data class Order(
    @SerializedName("before_download")
    val beforeDownload: Int = -1, // 下载前排序
    val installed: Int = -1, // 已安装排序
    val updatable: Int = -1, // 可更新排序
)

data class CoverTabEntity(
    @SerializedName("_id")
    var id: String = "",
    @SerializedName("game_id")
    var gameId: String = "",
    var name: String = "",
    var type: String = "", // tab显示内容(图集：gallery、视频：video)
    var select: Boolean = false, // 是否默认选中
    @SerializedName("video_link")
    var video: Video? = null,
    @SerializedName("gallery_info")
    var gallery: List<Gallery>? = null,
) {
    data class Gallery(
        var url: String = "",
        var width: String = "",
        var height: String = "",
    )

    data class Video(
        @SerializedName("_id", alternate = ["video_id"])
        var videoId: String = "",
        var poster: String = "",
        var title: String = "",
        var url: String = "",
    )
}

data class GameDetailDataInfo(
    val name: String = "", // 字段（ranking：榜单排名、size：游戏大小、recommend_age：适龄提示、language：语言、internet_app：需要联网、real_name：游戏内实名）
    @SerializedName("name_cn")
    val nameCn: String = "", // 字段中文
    val value: String = "", // 字段值

    val ranking: Ranking? = null, // 榜单排名
    val size: String = "", // 游戏大小
    @SerializedName("recommend_age")
    val recommendAge: String = "", // 适龄等级
    val language: String = "", // 语言
    @SerializedName("internet_app")
    val internetApp: String = "", // 是否联网
    @SerializedName("real_name")
    val realName: RealName? = null // 实名
) {
    data class Ranking(
        @SerializedName("collection_id")
        val collectionId: String = "", // 专题合集ID
        @SerializedName("collection_name")
        val collectionName: String = "", // 专题合集名称
        @SerializedName("column_id")
        val columnId: String = "", // 专题ID
        @SerializedName("column_name")
        val columnName: String = "", // 专题名称
        val no: Int = -1 // 名次
    )

    data class RealName(
        val state: String = "", // 是否需要游戏内实名
        @SerializedName("certification_screenshot")
        val certificationScreenshot: String = "" // 实名认证截图
    )
}

data class GameDetailInfoTag(
    @SerializedName("info_tags")
    val infoTags: List<InfoTag> = listOf(), // 功能标签
    @SerializedName("request_speed_status")
    val requestSpeedStatus: String = "", // 求加速状态, on/off
    @SerializedName("plugin_tutorial_link")
    val link: LinkEntity? = null, // 插件教程链接
) {
    @Parcelize
    data class InfoTag(
        val name: String = "", // 功能名称
        val des: String = "", // 功能说明
        val icon: String = "", // icon
        val color: String = "" // 颜色
    ): Parcelable
}

data class GameDetailLink(
    val title: String = "", // 标题
    @SerializedName("component_icon")
    val componentIcon: ComponentIcon? = null, // 组件图标
    val img: String = "", // 图片
    @SerializedName("img_scale")
    val imgScale: String = "", // 图片比例,2:1、4:1
    val text: String = "", // 跳转文案
    val link: LinkEntity? = null // 跳转链接
) {
    data class ComponentIcon(
        @SerializedName("_id")
        val id: String = "",
        val name: String = "",
        val icon: String = ""
    )
}

data class GameDetailComprehensivePanelEntity(
    val name: String = "",
    @SerializedName("show_name")
    val showName: Boolean = true,
    @SerializedName("comprehensive_data")
    val data: List<GameDetailComprehensivePanelItem>? = null,
)

data class GameDetailComprehensivePanelItem(
    val title: String = "", // 标题
    val type: String = "", // 板块类型（function：功能列表、FAQ：常见问题、declaration：声明信息）
    @SerializedName("show_title")
    val showTitle: Boolean = true, // 是否显示此标题（true：显示、false：隐藏）
    @SerializedName("function_type")
    val functionType: String = "", // 功能列表类型，type=function，（one_line_one_point：一行一分点、one_line_two_points：一行两分点）
    @SerializedName("show_type")
    val showType: String = "", // function_type=one_line_one_point, 一行一分点-显示内容（part：部分展开、all：展开全部）
    @SerializedName("show_row_num")
    val showRowNum: Int = 0, // show_type=part，一行一分点-显示内容-部分展开，填写展示分点数
    val data: List<ContentData>? = null, // 功能列表/常见问题 内容数据
    val declaration: String = "" // type=declaration时，才有此字段数据
) {
    data class ContentData(
        val text: String = "", // 文案/分点内容
        val link: LinkEntity? = null // 跳转链接，type=FAQ时填写
    )

    companion object {
        const val TYPE_FUNCTION = "function"
        const val TYPE_FAQ = "FAQ"
        const val TYPE_DECLARATION = "declaration"
        const val FUNCTION_TYPE_ONE_LINE_ONE_POINT = "one_line_one_point"
        const val FUNCTION_TYPE_ONE_LINE_TWO_POINTS = "one_line_two_points"
        const val SHOW_TYPE_PART = "part"
        const val SHOW_TYPE_ALL = "all"
    }
}

data class GameDetailLinksItem(
    val name: String = "", // 标题
    @SerializedName("show_name")
    val showName: Boolean = true,  // app是否显示组件标题（true：显示、false：隐藏）
    val data: List<GameDetailLink> = listOf()
)

data class GameBrief(
    val name: String = "", // 组件标题
    @SerializedName("game_tags")
    val gameTags: List<GameTag> = listOf(), // 游戏标签
    val des: String = "", // 游戏介绍
    @SerializedName("award_data")
    val awardData: List<AwardData> = listOf() // 奖项数据
) {
    data class GameTag(
        @SerializedName("_id")
        val id: String = "",
        @SerializedName("_seq")
        val seq: Int = 0,
        val name: String = "", // 功能名称
        val color: String = "", // 标签颜色
        val background: String = "", // 标签背景
        val column: String = "", // 排行榜专题标签颜色
        @SerializedName("is_top")
        val isTop: Boolean = false
    )

    data class AwardData(
        val icon: String = "", // 图标
        val award: String = "", // 奖项名称
        @SerializedName("award_type")
        val awardType: String = "", // 奖项类别
        val link: LinkEntity? = null // 通用链接
    )
}

data class GameDetailCustomColumn(
    val name: String = "", // 组件标题
    @SerializedName("show_name")
    val showName: Boolean = true, // 是否展示组件标题
    val img: String = "", // 图片
    @SerializedName("title_info")
    val titleInfo: TitleInfo? = null, // 栏目标题数据
    @SerializedName("right_top_info")
    val rightTopInfo: RightTopInfo? = null, // 右上角数据
    @SerializedName("second_title_info")
    val secondTitleInfo: SecondTitleInfo? = null, // 二级标题数据
    @SerializedName("show_des_type")
    val showDesType: String = "", // 显示内容（part：控制行数、all：展开全部）
    @SerializedName("show_des_row_num")
    val showDesRowNum: Int = 0, // 控制行数
    @SerializedName("tag_des")
    val tagDes: String = "" // 正文说明
) {
    var subPosition = -1 // 多个自定义栏目相邻时的排序(本地字段), -1表示单个无相邻
    var showBottomPadding = false

    data class TitleInfo(
        val icon: String = "", // 栏目标题前图标
        @SerializedName("icon_subscript")
        val iconSubscript: String = "", // 栏目标题前图标
        @SerializedName("icon_float")
        var iconFloat: IconFloat? = null,
        val title: String = "", // 栏目标题
        @SerializedName("show_title")
        val showTitle: Boolean = true, // 是否显示栏目标题
        val text: String = "", // 栏目标题后文案
        val link: LinkEntity? = null // 标题后文案跳转链接
    )

    data class RightTopInfo(
        val icon: String = "", // 右上角图标
        val style: String = "", // 文案样式（text：文本、button：按钮）
        val text: String = "", // 右上角文案
        val link: LinkEntity? = null // 右上角文案跳转链接
    ) {
        companion object {
            const val TYPE_TEXT = "text"
            const val TYPE_BUTTON = "button"
        }
    }

    data class SecondTitleInfo(
        val icon: String = "", // 二级标题前图标
        @SerializedName("show_title")
        val showTitle: Boolean = true, // 是否显示二级标题
        val text: String = "", // 二级标题内容
        val color: String = "" // 二级标题颜色
    )

    companion object {
        const val SHOW_DES_TYPE_PART = "part"
        const val SHOW_DES_TYPE_ALL = "all"
        const val SHOW_TYPE_RIGHT_TOP_TEXT_OR_NONE = "right_top_text_or_none"
        const val SHOW_TYPE_RIGHT_TOP_BUTTON = "right_top_button"
    }
}

data class DeveloperWord(
    val name: String = "",
    val text: String = "",
)

data class GameDetailUpdateContent(
    val name: String = "",
    @SerializedName("history_apk_count")
    val historyApkCount: Int = 0,
    @SerializedName("history_apk_status")
    var historyApkStatus: String = "",
    var date: String = "",
    var version: String = "",
    @SerializedName("update_des")
    var updateDes: String = ""
)

data class GameDetailComment(
    val name: String = "",
    @SerializedName("comment_data")
    val data: ArrayList<RatingComment> = arrayListOf()
)

@Parcelize
data class GameDetailInfo(
    val name: String = "",
    val fields: List<InfoItem> = listOf(),
    val des: String = ""
): Parcelable {
    @Parcelize
    data class InfoItem(
        val name: String = "",
        val type: String = "",
        val text: String = "",
        val key: String = "", // QQ群KEY
        val value: String = "",
        @SerializedName("is_first")
        val isFirst: Boolean = true, // 是否显示在一级页面
        val order: Int = -1, // 排序
        val permissions: List<Permission>? = null,
    ): Parcelable
}

data class GameDetailVideo(
    val video: List<Video> = listOf(), // 视频列表
    val count: Int = 0 // 视频数量
) {
    data class Video(
        @SerializedName("_id")
        val id: String = "",
        val poster: String = "", // 封面图
        val title: String = "",
        val url: String = "",
        val user: User? = null,
        val vote: Int = 0 // 点赞数
    )
}

data class GameDetailStrategy(
    val name: String = "", // 组件标题
    @SerializedName("right_top")
    val rightTop: String = "", // 右上角文案（more：更多、link：攻略链接）
    @SerializedName("article_types")
    val articleTypes: List<String> = listOf(), // 游戏文章类型
    @SerializedName("article_top")
    val articleTop: List<NewsEntity> = listOf(), // 置顶文章
    val data: List<StrategyData> = listOf() // 文章数据
) {
    data class StrategyData(
        val type: String = "", // 文章类型
        @SerializedName("link_article")
        val linkArticle: NewsEntity? = null, // 游戏文章
        @SerializedName("link_community_article")
        val linkCommunityArticle: ArticleEntity? = null, // 社区文章
        val isFixedTop: Boolean = false // 本地字段，是否置顶
    )
}

data class GameDetailRecommendImage(
    val title: String = "",
    val img: String = "",
    val link: LinkEntity? = null
)

data class GameDetailRecommendGame(
    @SerializedName("related_game")
    var relatedGames: ArrayList<GameDetailRelatedGame>? = null,//原推荐游戏
    @SerializedName("download_game")
    var downloadGames: ArrayList<String>? = null,// 下载推荐
    @SerializedName("install_game")
    var installGames: ArrayList<String>? = null,// 安装推荐
    var recommendedGames: SubjectEntity? = null,
)

data class GameDetailRecommendColumn(
    @SerializedName("column_id")
    var columnId: String = "",
    @SerializedName("title")
    var columnTitle: String = "",
    @SerializedName("display")
    var display: Display? = null,//右上角文案
    @SerializedName("size.index")
    var gameCount: Int = 0,//显示多少条数
    @SerializedName("column_game")
    var columnGames: ArrayList<GameEntity>? = null,
) {
    data class Display(
        var home: String = "",
        @SerializedName("more_link")
        var moreLink: LinkEntity? = null,
    )
}




