package com.adealink.weparty.webview.jsbridge.method

import com.adealink.frame.util.getRawType
import com.adealink.weparty.webview.jsbridge.callback.JSBridgeCallback
import java.lang.reflect.ParameterizedType

/**
 * JSNativeMethod不要使用匿名内部类形式
 */
interface JSNativeMethod<ReqData, ResData> {

    companion object {
        @Suppress("UNCHECKED_CAST")
        fun <T : Any, R : Any> classOfT(data: JSNativeMethod<T, R>): Class<T>? {
            val type = (data.javaClass.genericInterfaces[0] as? ParameterizedType)
                ?.actualTypeArguments?.get(0)
            return if (type == null) null else (getRawType(type) as? Class<T>)
        }
    }

    val methodName: String

    fun handleMethodCall(data: ReqData, callback: JSBridgeCallback<ResData>?)

}