package com.gh.common.interceptor

import com.gh.gamecenter.common.constant.RouteConsts
import com.halo.assistant.HaloApp
import com.therouter.router.RouteItem
import com.therouter.router.interceptor.RouterReplaceInterceptor
import com.therouter.router.matchRouteMap

/**
 * 主拦截器
 */
class MainInterceptor: RouterReplaceInterceptor()  {

    override fun replace(routeItem: RouteItem?): RouteItem? {
        if (routeItem == null) return null

        // 用户是否已经同意隐私政策
        val isUserAcceptPrivacyPolicy = HaloApp.isUserAcceptPrivacyPolicy(HaloApp.getInstance())

        // 如果用户已经同意隐私政策并且应用已经启动，直接返回 routeItem ，运行跳转
        if (isUserAcceptPrivacyPolicy && HaloApp.getInstance().isAlreadyUpAndRunning) {
            return routeItem
        }

        // 指向调整为 SplashScreenActivity
        return matchRouteMap(RouteConsts.activity.splashActivity)
    }

}