package com.yidian.shenghuoquan.bmanagercenter.app

import android.content.Intent
import com.yidian.bcommon.app.YdBaseApplication
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.CHOOSE_CAREER
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.CHOOSE_STORE_ACTIVITY
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH_INFO
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE_COMPLETE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH_COMPLETE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_IDENTITY
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_INFO
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_MODIFY_NAME
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH_COMPLETE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.MERCHANT_CENTER
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_ADD_STAFF
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_MANAGER_CHANGE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_MANAGER_INFO
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_MY_STAFF
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_STAFF_INFO
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.PERSONAL_STAFF_MANAGE
import com.yidian.bcommon.constant.XRouterPathConstants.Companion.STORE_MANAGEMENT
import com.yidian.bcommon.sdk.ClientType
import com.yidian.bcommon.sdk.JudgeClientUtils
import com.yidian.bcommon.services.ZapServiceNameConstants
import com.yidian.news.util.ProcessUtil
import com.yidian.nightmode.util.NightModeUtil
import com.yidian.shenghuoquan.bmanagercenter.personnel.ui.*
import com.yidian.shenghuoquan.bmanagercenter.service.LifeAccountManagerService
import com.yidian.shenghuoquan.bmanagercenter.service.LifeNumberListService
import com.yidian.shenghuoquan.bmanagercenter.service.SelectStoreService
import com.yidian.shenghuoquan.bmanagercenter.ui.auth.*
import com.yidian.shenghuoquan.bmanagercenter.ui.center.*
import com.yidian.shenghuoquan.bmanagercenter.ui.store.ChooseStoreActivity
import com.yidian.shenghuoquan.bmanagercenter.ui.store.StoreManagementActivity
import com.yidian.shenghuoquan.bmanagercenter.wallet.ui.*
import com.yidian.utils.DensityUtil
import com.yidian.xpage.XPageManager
import com.yidian.xpage.node.XPageHandler
import com.yidian.xpage.node.XPageNode
import com.yidian.xpage.node.XPageNodePageType
import com.yidian.yac.core.core.YacModuleSpec
import com.yidian.yac.core.zap.Zap

@YacModuleSpec
class BManagerCenterApplication : YdBaseApplication() {
  override fun onCreate() {
    super.onCreate()
    if (ProcessUtil.isMainProcess(this)) {
      registerXPage()
      initService()
      NightModeUtil.setContext(this)
      // 工具类的使用需要先初始化，后续才能用
      DensityUtil.init(this)
    }
  }

  private fun registerXPage() {
    XPageManager.registeredNodes(
      arrayListOf(
        XPageNode(STORE_MANAGEMENT, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, StoreManagementActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(CHOOSE_STORE_ACTIVITY, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, ChooseStoreActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_IDENTITY, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountIdentityActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_AUTH, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountAuthActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_PERSONAL_AUTH, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountPersonalAuthActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_ENTERPRISE_AUTH, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountEnterpriseAuthActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_PERSONAL_AUTH_COMPLETE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountPersonalAuthCompleteActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_ENTERPRISE_AUTH_COMPLETE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountEnterpriseAuthCompleteActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_CREATE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountCreateActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_CREATE_COMPLETE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountCreateCompleteActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(CHOOSE_CAREER, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, ChooseCareerActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_MY_STAFF, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MyStaffActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_MANAGER_INFO, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, ManagerInfoActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_MANAGER_CHANGE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, ManagerChangeActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_STAFF_INFO, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, StaffInfoActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_STAFF_MANAGE, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, StaffManageActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(PERSONAL_ADD_STAFF, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, AddStaffActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(MERCHANT_CENTER, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MerchantCenterActivity::class.java)
            // 兼容B&C端
            if (JudgeClientUtils.judgeClient(packageName) == ClientType.MERCHANT_B) {
              intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
            } else {
              // 同SingleTask
              intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
            }
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_INFO, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MerchantInfoActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_MODIFY_NAME, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, LifeAccountModifyNameActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(LIFE_ACCOUNT_AUTH_INFO, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MerchantAuthInfoActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.MY_WALLET, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MyWalletActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.VERIFY_IDENTITY, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, VerifyIdentityActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.WECHAT_AUTH, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, WeChatAuthActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.WITHDRAW, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, WithdrawActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.TRANSACTION_LIST, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, TransactionListActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.TRANSACTION_DETAILS, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, TransactionDetailsActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.AUTH_MANAGEMENT, XPageNodePageType.NATIVE, object : XPageHandler {
          override fun handler(params: Map<String, Any?>?) {
            val intent = Intent()
            if (params != null) {
              intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
            }
            intent.setClass(context, MerchantAuthManagementActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
      )
    )
  }

  private fun initService() {
    Zap.addService(ZapServiceNameConstants.LifeNumberListService, LifeNumberListService())
    Zap.addService(SelectStoreService.serviceName, SelectStoreService())
    Zap.addService(ZapServiceNameConstants.LifeAccountManagerService, LifeAccountManagerService())
  }

}
