package com.qmth.sop.server.api;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.sync.FxxkApiUtils;
import com.qmth.sop.business.sync.been.fxxk.FxxkAppAuthInfo;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: 分享逍客同步控制器
 * @Author: CaoZixuan
 * @Date: 2023-10-28
 */
@Api(tags = "纷享销客数据同步 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_FXXK)
public class FxxkAsyncController {
    @Resource
    FxxkApiUtils fxxkApiUtils;

    @ApiOperation(value = "纷享销客数据推送接口（接收）")
    @ApiResponses({@ApiResponse(code = 200, message = "数据推送接口", response = Object.class)})
    @RequestMapping(value = "/data/push", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @Aac(auth = false)
    public Result crmCallBack(@RequestBody String arg) {
        System.out.println(arg);
        return ResultUtil.ok();
    }

    @ApiOperation(value = "纷享销客-获取应用级授权信息")
    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = FxxkAppAuthInfo.class)})
    @RequestMapping(value = "/app/auth/info", method = RequestMethod.POST)
    @Aac(auth = false)
    public Result findFxxkAppAuthInfo() {
        return ResultUtil.ok(fxxkApiUtils.findFxxkAppAuthInfo());
    }

    @ApiOperation(value = "纷享销客-根据手机号获取openUserId")
    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = String.class)})
    @RequestMapping(value = "/find/open_user_id", method = RequestMethod.POST)
    @Aac(auth = false)
    public Result findCurrentOpenUserId() {
        return ResultUtil.ok(fxxkApiUtils.findCurrentOpenUserId());
    }

    @ApiOperation(value = "纷享销客-查询单个用户信息")
    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = Result.class)})
    @RequestMapping(value = "/find/user_info", method = RequestMethod.POST)
    @Aac(auth = false)
    public Result findUserInfo(@RequestParam String userId) {
        return ResultUtil.ok(fxxkApiUtils.findFxxkUserById(userId));
    }

    @ApiOperation(value = "纷享销客-查询自定义对象列表")
    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = Result.class)})
    @RequestMapping(value = "/find/custom_list", method = RequestMethod.POST)
    @Aac(auth = false)
    public Result findCustomList() {
        return ResultUtil.ok(fxxkApiUtils.findCustomList());
    }
}