package cn.hanghui.outapi.platform.xinghuo.controller;

import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeApplyReq;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeApplyResp;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeEncryptReq;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeEncryptResp;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeUserInfoReq;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.SpecialCodeUserInfoResp;
import cn.hanghui.outapi.platform.xinghuo.service.ProofOpenApiService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.xinghuo.controller
 * @class ProofOpenApiController
 * @date 2024/7/30 下午2:47
 * @description 临时身份证明开放接口
 */
@Slf4j
@Api(tags = "临证开放接口")
@RestController
@RequestMapping("/v1/proof")
public class ProofOpenApiController {

    @Autowired
    private ProofOpenApiService proofOpenApiService;

    @ApiOperation("根据三要素获取二维码（非加密版）")
    @PostMapping("/special/code/apply")
    public RestResult<SpecialCodeApplyResp> applySpecialCode(@RequestBody SpecialCodeApplyReq req) {
        log.info("根据三要素获取二维码非加密版原始入参：{}", JSONObject.toJSONString(req));
        return RestResult.ok(proofOpenApiService.applySpecialCode(req));
    }

    @ApiOperation("根据三要素获取二维码（加密版）")
    @PostMapping("/special/code/apply/encrypt")
    public RestResult<SpecialCodeEncryptResp> applySpecialCodeEncrypt(@RequestBody SpecialCodeEncryptReq req) {
        log.info("根据三要素获取二维码加密版原始入参：{}", JSONObject.toJSONString(req));
        return RestResult.ok(proofOpenApiService.applySpecialCodeEncrypt(req));
    }

    @ApiOperation("根据二维码换取三要素(支付宝小程序调用)")
    @PostMapping("/mini/user/info/query")
    public RestResult<SpecialCodeUserInfoResp> queryUserInfoByMiniSpecialCode(@RequestBody SpecialCodeUserInfoReq req) {
        log.info("支付宝小程序调用-根据二维码换取三要素原始入参：{}", JSONObject.toJSONString(req));
        return RestResult.ok(proofOpenApiService.queryUserInfoByMiniSpecialCode(req));
    }

    @ApiOperation("根据二维码换取三要素(设备端调用)")
    @PostMapping("/user/info/query")
    public RestResult<SpecialCodeUserInfoResp> queryUserInfoBySpecialCode(@RequestBody SpecialCodeUserInfoReq req) {
        log.info("设备端调用-根据二维码换取三要素原始入参：{}", JSONObject.toJSONString(req));
        return RestResult.ok(proofOpenApiService.queryUserInfoBySpecialCode(req));
    }

    @ApiOperation("根据二维码换取三要素（加密版）")
    @PostMapping("/qrcode/encrypt/queryUserInfo")
    public RestResult<SpecialCodeEncryptResp> queryUserInfoBySpecialCodeEncrypt(@RequestBody SpecialCodeEncryptReq req) {
        log.info("根据二维码换取三要素加密版原始入参：{}", JSONObject.toJSONString(req));
        return RestResult.ok(proofOpenApiService.queryUserInfoBySpecialCodeEncrypt(req));
    }


}
