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.constant.HawkConfig
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.base.BaseActivity
import com.yidian.shenghuoquan.bmanagercenter.constant.Constant
import com.yidian.shenghuoquan.bmanagercenter.databinding.ActivityMerchantAuthInfoBinding
import com.yidian.shenghuoquan.bmanagercenter.http.httpbean.GetLifeAccountInfoByIdBean

/**
 * 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 (lifeAccountInfo?.id_type) {
      Constant.TYPE_AUTH_PERSONAL -> {
        // 个人认证
        viewBind.ivPersonAuthInfo.isVisible = true
        viewBind.ivPersonAuthInfo.fillAuthInfo(
          lifeAccountInfo?.life_account_name,
          lifeAccountInfo?.occupation,
          lifeAccountInfo?.legal_person,
          lifeAccountInfo?.id_card,
          Hawk.get(HawkConfig.Mobile)
        )
      }
      Constant.TYPE_AUTH_INDIVIDUAL_BUSINESS -> {
        // 个人工商户认证
        viewBind.ivEnterpriseAuthInfo.isVisible = true
        viewBind.ivEnterpriseAuthInfo.fillAuthInfo(
          lifeAccountInfo?.id_type,
          lifeAccountInfo?.audit_status,
          lifeAccountInfo?.name,
          lifeAccountInfo?.code,
          lifeAccountInfo?.legal_person,
          lifeAccountInfo?.id_card
        )
      }
      Constant.TYPE_AUTH_COMMON_ENTERPRISE -> {
        // 普通企业认证
        viewBind.ivEnterpriseAuthInfo.isVisible = true
        viewBind.ivEnterpriseAuthInfo.fillAuthInfo(
          lifeAccountInfo?.id_type,
          lifeAccountInfo?.audit_status,
          lifeAccountInfo?.name,
          lifeAccountInfo?.code,
          lifeAccountInfo?.legal_person,
          lifeAccountInfo?.id_card
        )
      }
    }
  }
}
