package com.yidian.shenghuoquan.bmanagercenter.service

import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.shenghuoquan.bmanagercenter.manager.LifeAccountManager
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import org.json.JSONObject

/**
 * author: yinjiacheng
 * date: 2021/8/19 08:44
 * description: 生活号管理服务
 */
class LifeAccountManagerService : ZapService() {

  override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
    when (action) {
      // 获取生活号id
      ZapServiceActionConstants.ActionGetLifeAccountId -> {
        resolver.success(JSONObject().put("lifeAccountId", LifeAccountManager.getLifeAccountId()))
      }
      // 保存生活号id
      ZapServiceActionConstants.ActionSaveLifeAccountId -> {
        LifeAccountManager.saveLifeAccountId((params as JSONObject).optString("lifeAccountId"))
      }
      // 清空生活号id
      ZapServiceActionConstants.ActionDeleteLifeAccountId -> {
        LifeAccountManager.deleteLifeAccountId()
      }
    }
  }

  override fun onExit() {

  }

  override fun onInit() {

  }
}
