package com.gh.gamecenter.qa.article.detail

import android.content.Context
import android.content.Intent
import com.therouter.router.Route
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.CommunityEntity
import com.gh.gamecenter.entity.SpecialColumn

/**
 * 帖子详情
 */
@Route(path = RouteConsts.activity.articleDetailActivity)
class ArticleDetailActivity : ToolBarActivity() {

    override fun getLayoutId() = R.layout.activity_amway

    override fun getFragmentPlaceholderId() = R.id.placeholder

    override fun provideNormalIntent(): Intent {
        return getTargetIntent(this, ArticleDetailActivity::class.java, ArticleDetailFragment::class.java)
    }

    override fun getBusinessId(): Pair<String, String> {
        return Pair(
            targetFragment.arguments?.getString(EntranceConsts.KEY_COMMUNITY_ARTICLE_ID) ?: "",
            targetFragment.arguments?.getParcelable<CommunityEntity>(EntranceConsts.KEY_COMMUNITY_DATA)?.id ?: ""
        )
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    companion object {
        const val ARTICLE_PATCH_REQUEST = 123

        @JvmStatic
        fun getIntent(
            context: Context,
            community: CommunityEntity,
            articleId: String,
            entrance: String,
            path: String,
            specialColumn: SpecialColumn? = null,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, ArticleDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_ARTICLE_ID, articleId)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_DATA, community)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_DATA, specialColumn)
            return intent
        }

        /**
         * 自动滚动到评论区域
         */
        @JvmStatic
        fun getCommentIntent(
            context: Context,
            community: CommunityEntity,
            articleId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, ArticleDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_ARTICLE_ID, articleId)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_DATA, community)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            return intent
        }

        @JvmStatic
        fun getRecommendIntent(
            context: Context,
            community: CommunityEntity,
            articleId: String,
            recommendId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, ArticleDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_ARTICLE_ID, articleId)
            intent.putExtra(EntranceConsts.KEY_RECOMMEND_ID, recommendId)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_DATA, community)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }

        /**
         * 定位到指定的评论并置顶
         */
        @JvmStatic
        fun getSpecifiedCommentIntent(
            context: Context,
            community: CommunityEntity,
            articleId: String,
            topCommentId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, ArticleDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_ARTICLE_ID, articleId)
            intent.putExtra(EntranceConsts.KEY_COMMUNITY_DATA, community)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_TOP_COMMENT_ID, topCommentId)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            return intent
        }
    }
}