package com.ydl.js_module.util

import android.text.TextUtils

/**
 * @author yuanWai
 * @描述:webview路由工具类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/5
 */
class WebViewRouterUtils{

    companion object {
        private var ydlRouterUrl = "ydl-user://"
        private var ydlRouterUrl2 = "ydl-zixun://"
        private var ydlRouterUrl3 = "ydl-test://"
        //todo 方法名称 后期会去掉这个路由 替换成 ydl-router统一处理 过渡方案
        private var METHOD_1 = "test/detail"
        private var METHOD_2 = "test/result"
        private var METHOD_3 = "test/pay"
        private var METHOD_4 = "test/list"

        /**
         * 是否符合路由规则
         */
        fun isRouterUrl(url : String) : Boolean{
            if (TextUtils.isEmpty(url)){
                return false
            }
            if (url.contains(ydlRouterUrl) && containsMethod(url)){
                return true
            }
            if (url.contains(ydlRouterUrl2) && containsMethod(url)){
                return true
            }
            if (url.contains(ydlRouterUrl3) && containsMethod(url)){
                return true
            }
            return false
        }

        /**
         * 是否包含下列方法
         */
        private fun containsMethod(url : String) : Boolean{
            return (url.contains(METHOD_1) || url.contains(METHOD_2) || url.contains(METHOD_3) || url.contains(METHOD_4))
        }
    }
}