package com.yidian.shenghuoquan.bmanagercenter.ui.center

import android.os.Bundle
import androidx.core.view.isVisible
import com.orhanobut.hawk.Hawk
import com.yidian.bcommon.base.BaseActivity
import com.yidian.bcommon.constant.HawkConfig
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.sdk.BCommonManager
import com.yidian.shenghuoquan.bmanagercenter.databinding.ActivityMerchantAuthInfoBinding
import com.yidian.shenghuoquan.bmanagercenter.http.httpbean.GetLifeAccountInfoByIdBean
import com.yidian.shenghuoquan.bmanagercenter.manager.LifeAccountManager

/**
 * author: yinjiacheng
 * date: 6/15/21 9:52 AM
 * description: 商户认证信息详情页
 */
class MerchantAuthInfoActivity : BaseActivity<ActivityMerchantAuthInfoBinding>() {

  companion object {
    const val EXTRA_LIFE_ACCOUNT_INFO = "life_account_info"
  }

  /**
   * 生活号详情
   */
  private val lifeAccountInfo by lazy {
    intent.getSerializableExtra(XRouterPathConstants.ParamsKey)?.let { params ->
      (params as HashMap<*, *>)[EXTRA_LIFE_ACCOUNT_INFO]?.let {
        it as GetLifeAccountInfoByIdBean.Response
      }
    }
  }

  override fun createViewBinding(): ActivityMerchantAuthInfoBinding {
    return ActivityMerchantAuthInfoBinding.inflate(layoutInflater)
  }

  override fun getXPageName(): String {
    return XRouterPathConstants.LIFE_ACCOUNT_AUTH_INFO
  }

  override fun init(savedInstanceState: Bundle?) {
    super.init(savedInstanceState)
    initData()
  }

  private fun initData() {
    when (LifeAccountManager.getLifeAccountTag(lifeAccountInfo?.tag?.tag_key)) {
      LifeAccountManager.LifeAccountTag.LIFE_ACCOUNT_TAG_COMMON_ENTERPRISE_AUTH, LifeAccountManager.LifeAccountTag.LIFE_ACCOUNT_TAG_INDIVIDUAL_BUSINESS_AUTH, LifeAccountManager.LifeAccountTag.LIFE_ACCOUNT_TAG_AUDIT_UNDER -> {
        // 普通企业认证、个体工商户认证、审核中
        viewBind.ivEnterpriseAuthInfo.isVisible = true
        viewBind.ivEnterpriseAuthInfo.fillAuthInfo(
          lifeAccountInfo?.tag?.tag_key,
          lifeAccountInfo?.id_type,
          lifeAccountInfo?.name,
          lifeAccountInfo?.code,
          lifeAccountInfo?.legal_person,
          lifeAccountInfo?.id_card
        )
      }
      LifeAccountManager.LifeAccountTag.LIFE_ACCOUNT_TAG_PERSONAL_AUTH -> {
        // 个人认证
        viewBind.ivPersonAuthInfo.isVisible = true
        viewBind.ivPersonAuthInfo.fillAuthInfo(
          lifeAccountInfo?.life_account_name,
          lifeAccountInfo?.occupation,
          lifeAccountInfo?.legal_person,
          lifeAccountInfo?.id_card,
          BCommonManager.getUserPhone() ?: Hawk.get(HawkConfig.Mobile)
        )
      }
    }
  }
}
