package com.yidian.shenghuoquan.newscontent.app

import android.content.Intent
import com.yidian.common.XRouterPathConstants
import com.yidian.common.XRouterPathConstants.Companion.CHOOSE_CAREER
import com.yidian.common.XRouterPathConstants.Companion.CHOOSE_STORE_ACTIVITY
import com.yidian.common.XRouterPathConstants.Companion.FLASH
import com.yidian.common.XRouterPathConstants.Companion.ID_CARD_TEST
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_AUTH
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_CREATE_COMPLETE
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_AUTH_COMPLETE
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_IDENTITY
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_MODIFY_NAME
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH
import com.yidian.common.XRouterPathConstants.Companion.LIFE_ACCOUNT_PERSONAL_AUTH_COMPLETE
import com.yidian.common.XRouterPathConstants.Companion.LOGIN_LIFE_CIRCLE
import com.yidian.common.XRouterPathConstants.Companion.MERCHANT_AUTH_INFO
import com.yidian.common.XRouterPathConstants.Companion.MERCHANT_CENTER
import com.yidian.common.XRouterPathConstants.Companion.MERCHANT_INFO
import com.yidian.common.XRouterPathConstants.Companion.NEWS_CONTENT
import com.yidian.common.XRouterPathConstants.Companion.NEWS_MAIN
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_ADD_STAFF
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_MANAGER_CHANGE
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_MANAGER_INFO
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_MY_STAFF
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_STAFF_INFO
import com.yidian.common.XRouterPathConstants.Companion.PERSONAL_STAFF_MANAGE
import com.yidian.common.XRouterPathConstants.Companion.PROTOCOL
import com.yidian.common.XRouterPathConstants.Companion.STORE_MANAGEMENT
import com.yidian.common.XRouterPathConstants.Companion.SUPPORT
import com.yidian.common.XRouterPathConstants.Companion.SYSTEM_SETTING
import com.yidian.common.YdBaseApplication
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.*
import com.yidian.shenghuoquan.newscontent.ui.*
import com.yidian.shenghuoquan.newscontent.ui.auth.*
import com.yidian.shenghuoquan.newscontent.ui.center.*
import com.yidian.shenghuoquan.newscontent.ui.idcard.IDCardTestActivity
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(FLASH, 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, FlashActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),
        XPageNode(NEWS_MAIN, 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, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),

        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(ID_CARD_TEST, 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, IDCardTestActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
          }
        }),

        XPageNode(LIFE_ACCOUNT_ENTERPRISE_CERTIFICATION, 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, LifeAccountEnterpriseCertificationActivity::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(NEWS_CONTENT, 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, NewsContentActivity::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(SUPPORT, 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, ProductSupportActivity::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(MERCHANT_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(MERCHANT_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.MERCHANT_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(RequestService.serviceName, RequestService())
    Zap.addService(CommentService.serviceName, CommentService())
    Zap.addService(UniversalService.serviceName, UniversalService())
    Zap.addService(UserService.serviceName, UserService())
    Zap.addService(CacheService.serviceName, CacheService())
    Zap.addService(DeepLinkService.serviceName, DeepLinkService())
    Zap.addService(SelectStoreService.serviceName, SelectStoreService())
  }
}
