package com.yidian.shenghuoquan.bdemo.service

import com.yidian.bcommon.services.ZapServiceActionConstants
import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.yac.core.zap.ZapService
import com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import org.json.JSONObject

/**
 * author: yinjiacheng
 * date: 7/30/21 4:27 PM
 * description: C端客户端信息服务
 */
class ClientInfoService : ZapService() {

  override fun onAction(path: String, action: String, params: Any, options: Any, resolver: ResultResolver) {
    when (action) {
      // 获取C端userId、userName、userPhone
      ZapServiceActionConstants.ActionGetUserInfo -> {
        resolver.success(
          JSONObject()
            .put("userId", "510227073302")
            .put("userName", "yjc0314")
            .put("userPhone", "15054298387")
        )
      }
      // 获取C端网络请求公共参数
      ZapServiceActionConstants.ActionGetRequestPublicParameters -> {
        resolver.success(
          JSONObject()
            .put("appid", "merchant-c")
            .put("cv", "1.0.0")
            .put("version", "001000")
            .put("distribution", "official")
            .put("net", "wifi")
            .put("platform", "1")
            .put("device_finger", FtDeviceFingerManager.getDeviceFinger())
            .put(
              "reqid", StringBuilder()
                .append("merchant-c")
                .append('_')
                .append(FtDeviceFingerManager.getDeviceFinger())
                .append('_')
                .append(System.currentTimeMillis())
                .toString()
            )
        )
      }
      // 获取C端经纬度
      ZapServiceActionConstants.ActionGetCurrentLocation -> {
        resolver.success(
          JSONObject()
            .put("longitude", 116.4955500)
            .put("latitude", 39.9885500)
            .put("address", "北京市朝阳区酒仙桥")
        )
      }
    }
  }

  override fun onExit() {

  }

  override fun onInit() {

  }
}
