package com.yidian.shenghuoquan.newscontent.service

import com.yidian.common.XEventConfig.Companion.GO_TO_COMMENT_DETAIL
import com.yidian.common.XEventConfig.Companion.REPLY_COMMENT
import com.yidian.common.XEventConfig.Companion.REPLY_DETAIL_COMMENT
import com.yidian.common.XEventConfig.Companion.UPDATE_COMMENT
import com.yidian.common.XEventConfig.Companion.UPDATE_LIKE
import com.yidian.common.utils.ToolsUtil
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import org.json.JSONObject

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

    private lateinit var resolver: ResultResolver

    override fun onAction(name: String, action: String, params: Any, options: Any, resolver: ResultResolver) {

        when (action) {
            REPLY_COMMENT -> {
                ToolsUtil.doAction(REPLY_COMMENT, params)
            }
            GO_TO_COMMENT_DETAIL -> {
                ToolsUtil.doAction(GO_TO_COMMENT_DETAIL, params)
            }
            REPLY_DETAIL_COMMENT -> {
                ToolsUtil.doAction(REPLY_DETAIL_COMMENT, params)
            }
            UPDATE_COMMENT -> {
                ToolsUtil.doAction(UPDATE_COMMENT, params)
            }
            UPDATE_LIKE -> {
                ToolsUtil.doAction(UPDATE_LIKE, params)
            }
        }

        this.resolver = resolver
        params as JSONObject
        val path = params.optString("name")
        val body = params.optJSONObject("body")
        when (action) {
            "addComment" -> addComment(path, body)
            "like" -> like(path, body)
        }
    }

    override fun onExit() {

    }

    override fun onInit() {

    }

    private fun addComment(path: String, params: JSONObject) {

    }

    private fun like(path: String, params: JSONObject) {

    }
}