package com.gh.gamecenter.setting.view.security

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.therouter.router.Route
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.utils.updateStatusBarColor
import com.gh.gamecenter.setting.entity.ConflictUserEntity

/**
 * 绑定手机
 */
@Route(path = RouteConsts.activity.bindPhoneActivity)
class BindPhoneActivity : ToolBarActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
    }

    override fun isAutoResetViewBackgroundEnabled() = true

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()
        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
    }

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

    companion object {

        const val RESULT_FINISH_CODE = 411

        @JvmStatic
        fun getNormalIntent(context: Context, isChangePhone: Boolean): Intent {
            return getIntent(context, isFromLogin = false, isChangePhone = isChangePhone)
        }

        // 第三方登录成功跳转绑定手机专用
        @JvmStatic
        fun getLoginSuccessIntent(context: Context): Intent {
            return getIntent(context, isFromLogin = true, isChangePhone = false)
        }

        @JvmStatic
        fun getIntent(context: Context, isFromLogin: Boolean, isChangePhone: Boolean): Intent {
            val bundle = Bundle()
            bundle.putBoolean(EntranceConsts.KEY_FROM_LOGIN, isFromLogin)
            bundle.putBoolean(EntranceConsts.KEY_CHANGE_PHONE, isChangePhone)
            return getTargetIntent(context, BindPhoneActivity::class.java, BindPhoneFragment::class.java, bundle)
        }

        // 绑定或者换绑手机号过程中出现手机号冲突专用
        @JvmStatic
        fun getBindPhoneConflictIntent(context: Context, phoneNum: String, conflictUser: ConflictUserEntity): Intent {
            val bundle = Bundle()
            bundle.putString(EntranceConsts.KEY_CONFLICT_PHONE, phoneNum)
            bundle.putParcelable(EntranceConsts.KEY_CONFLICT_USER, conflictUser)
            return getTargetIntent(
                context,
                BindPhoneActivity::class.java,
                BindPhoneConflictFragment::class.java,
                bundle
            )
        }
    }
}