package com.yidian.shenghuoquan.newscontent.service

import com.yidian.common.XRouterPathConstants
import com.yidian.shenghuoquan.newscontent.ui.NewsContentActivity
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.xpage.XPageManager
import com.yidian.yac.core.zap.ZapService
import org.json.JSONObject

class DeepLinkService: ZapService(){
    companion object{
        const val serviceName: String = "DeepLinkService"
    }

    private lateinit var resolver: ResultResolver

    override fun onAction(name: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
        this.resolver = resolver
        params as JSONObject
        val parameters = params.optJSONObject("parameters")
        when(params.optString("path")){
            "ydnews" -> jumpNewsText(parameters)
            "ydvideo" -> jumpNewsVideo(parameters)
            "ydauthor" -> jumpAuthorHomePage(parameters)
        }
    }

    override fun onExit() {

    }

    override fun onInit() {

    }

    private fun jumpNewsText(params: JSONObject){
        val docId = params.optString("docid")
        val paramsMap = HashMap<String, Any?>()
        paramsMap[NewsContentActivity.ContentType] = NewsContentActivity.TextType
        paramsMap[NewsContentActivity.DocId] = docId
        XPageManager.push(XRouterPathConstants.NEWS_CONTENT, paramsMap)
    }

    private fun jumpNewsVideo(params: JSONObject){
        val docId = params.optString("docid")
        val paramsMap = HashMap<String, Any?>()
        paramsMap[NewsContentActivity.ContentType] = NewsContentActivity.VideoType
        paramsMap[NewsContentActivity.DocId] = docId
        XPageManager.push(XRouterPathConstants.NEWS_CONTENT, paramsMap)
    }

    private fun jumpAuthorHomePage(params: JSONObject){
        val fromId = params.optString("fromid")
        val paramsMap = HashMap<String, Any?>()
    }
}