package com.yidian.shenghuoquan.bsetting.service

import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.shenghuoquan.bsetting.http.SettingRemoteDataSource
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import org.json.JSONObject

/**
 * 设置相关的服务
 */
class SettingService : ZapService() {

  private lateinit var resolver: ResultResolver

  override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
    this.resolver = resolver
    params as JSONObject
    when (action) {
      ZapServiceActionConstants.ActionLogout -> requestLogout()
    }
  }

  override fun onExit() {
  }

  override fun onInit() {
  }

  /**
   * 请求退出登录
   */
  private fun requestLogout() {
    SettingRemoteDataSource.userLogout {
      if (it) {
        resolver.success(it)
      }
    }
  }

}
