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

import cn.hanghui.outapi.platform.common.entity.rest.Result;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.GetProofByQrCodeDto;
import cn.hanghui.outapi.platform.xinghuo.entity.param.ApplyProofApiResult;
import cn.hanghui.outapi.platform.xinghuo.entity.param.GetQrCodeApiResult;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.ApplyProofDto;
import cn.hanghui.outapi.platform.xinghuo.entity.dto.GetQrCodeDto;
import cn.hanghui.outapi.platform.xinghuo.entity.param.GetProofByQrCodeApiResult;
import cn.hanghui.outapi.platform.xinghuo.service.XinghuoApiService;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "星火API服务")
@RestController
@RequestMapping("xinghuoApi")
@AllArgsConstructor(onConstructor_ = @Autowired)
public class XinghuoApiController {

    private final XinghuoApiService xinghuoApiService;

    /**
     * 申请凭证
     *
     * @param applyProofDto ApplyProofDto
     * @return Result<ApplyProofApiResult>
     */
    @ApiOperation("申请凭证")
    @PostMapping("applyProof")
    public Result<ApplyProofApiResult> applyProof(@RequestBody ApplyProofDto applyProofDto) {
        log.info("申请凭证请求参数：" + JSON.toJSONString(applyProofDto));
        return Result.ok(xinghuoApiService.applyProof(applyProofDto));
    }

    /**
     * 获取二维码
     *
     * @param getQrCodeDto GetQrCodeDto
     * @return Result<GetQrCodeApiResult>
     */
    @ApiOperation("获取二维码")
    @PostMapping("getQrCode")
    public Result<GetQrCodeApiResult> getQrCode(@RequestBody GetQrCodeDto getQrCodeDto) {
        return Result.ok(xinghuoApiService.getQrCode(getQrCodeDto));
    }

    /**
     * 根据二维码获取凭证信息
     *
     * @param getProofByQrCodeDto GetProofByQrCodeDto
     * @return Result<GetProofByQrCodeApiResult>
     */
    @ApiOperation("根据二维码获取凭证信息")
    @PostMapping("getProofByQrCode")
    public Result<GetProofByQrCodeApiResult> getProofByQrCode(@RequestBody GetProofByQrCodeDto getProofByQrCodeDto) {
        log.info("根据二维码获取凭证信息请求参数：" + JSON.toJSONString(getProofByQrCodeDto));
        return Result.ok(xinghuoApiService.getProofByQrCode(getProofByQrCodeDto));
    }
}
