package com.yidian.shenghuoquan.newscontent.app

import android.content.Intent
import com.yidian.bcommon.XRouterPathConstants
import com.yidian.bcommon.XRouterPathConstants.Companion.CHOOSE_CAREER
import com.yidian.bcommon.XRouterPathConstants.Companion.CHOOSE_STORE_ACTIVITY
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH_INFO
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE_COMPLETE
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH_COMPLETE
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_IDENTITY
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_INFO
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_MODIFY_NAME
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH
import com.yidian.bcommon.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH_COMPLETE
import com.yidian.bcommon.XRouterPathConstants.Companion.LOGIN_LIFE_CIRCLE
import com.yidian.bcommon.XRouterPathConstants.Companion.MERCHANT_CENTER
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_ADD_STAFF
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_MANAGER_CHANGE
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_MANAGER_INFO
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_MY_STAFF
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_STAFF_INFO
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_STAFF_MANAGE
import com.yidian.bcommon.XRouterPathConstants.Companion.PROTOCOL
import com.yidian.bcommon.XRouterPathConstants.Companion.STORE_MANAGEMENT
import com.yidian.bcommon.XRouterPathConstants.Companion.SYSTEM_SETTING
import com.yidian.bcommon.YdBaseApplication
import com.yidian.bcommon.services.ZapServiceNameConstants
import com.yidian.news.util.ProcessUtil
import com.yidian.nightmode.util.NightModeUtil
import com.yidian.shenghuoquan.newscontent.personnel.ui.*
import com.yidian.shenghuoquan.newscontent.service.LifeNumberListService
import com.yidian.shenghuoquan.newscontent.service.SelectStoreService
import com.yidian.shenghuoquan.newscontent.ui.LoginLifeCircleActivity
import com.yidian.shenghuoquan.newscontent.ui.ProtocolActivity
import com.yidian.shenghuoquan.newscontent.ui.auth.*
import com.yidian.shenghuoquan.newscontent.ui.center.*
import com.yidian.shenghuoquan.newscontent.ui.setting.FeedbackActivity
import com.yidian.shenghuoquan.newscontent.ui.setting.SystemSettingActivity
import com.yidian.shenghuoquan.newscontent.ui.store.ChooseStoreActivity
import com.yidian.shenghuoquan.newscontent.ui.store.StoreManagementActivity
import com.yidian.shenghuoquan.newscontent.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 NewsContentApplication : 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(LOGIN_LIFE_CIRCLE, 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, LoginLifeCircleActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        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(PROTOCOL, 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, ProtocolActivity::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(SYSTEM_SETTING, 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, SystemSettingActivity::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)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK 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)
          }
        }),
        XPageNode(XRouterPathConstants.Companion.FEEDBACK, 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, FeedbackActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
      )
    )
  }

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

  }
}
