package com.yidian.shenghuoquan.newscontent.ui.center

import android.os.Bundle
import androidx.core.view.isVisible
import com.orhanobut.hawk.Hawk
import com.yidian.bcommon.HawkConfig
import com.yidian.bcommon.XRouterPathConstants
import com.yidian.bcommon.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.constant.Constant
import com.yidian.shenghuoquan.newscontent.databinding.ActivityMerchantAuthInfoBinding
import com.yidian.shenghuoquan.newscontent.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
        )
      }
    }
  }
}
