package com.gh.gamecenter.qa.questions.newdetail

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

/**
 * 提问详情
 */
@Route(path = RouteConsts.activity.questionDetailActivity)
class NewQuestionDetailActivity : ToolBarActivity() {

    override fun getLayoutId() = R.layout.activity_amway

    override fun getFragmentPlaceholderId() = R.id.placeholder

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

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

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    companion object {
        @JvmStatic
        fun getIntent(
            context: Context,
            questionId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            return intent
        }

        /**
         * 自动滚动到评论区域
         */
        @JvmStatic
        fun getCommentIntent(
            context: Context,
            questionId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = ""
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            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 getCommentIntent(
            context: Context,
            questionId: String,
            answerId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = ""
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_ANSWER_ID, answerId)
            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,
            questionId: String,
            answerId: String,
            recommendId: String,
            entrance: String,
            path: String,
            scrollToComment: Boolean = false,
            sourceEntrance: String = "",
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_ANSWER_ID, answerId)
            intent.putExtra(EntranceConsts.KEY_RECOMMEND_ID, recommendId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, scrollToComment)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            return intent
        }

        @JvmStatic
        fun getSpecifiedCommentIntent(
            context: Context,
            questionId: String,
            topCommentId: String,
            entrance: String,
            path: String,
            sourceEntrance: String = ""
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_TOP_COMMENT_ID, topCommentId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            return intent
        }
    }
}