package cn.freemud.controller;

import cn.freemud.base.entity.BaseResponse;
import cn.freemud.entities.vo.PutDeadLetterVo;
import cn.freemud.service.impl.PayServiceImpl;
import cn.freemud.utils.ResponseUtil;
import com.freemud.application.sdk.api.log.ApiAnnotation;
import com.freemud.application.sdk.api.log.LogParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 暴露订单相关的业务接口,提供给applet项目
 */
@RestController
@RequestMapping("/exposure")
public class ExposureOrderController {

    @Autowired
    private PayServiceImpl payService;

    /**
     * 创建支付单,查询支付配置
     */
    @ApiAnnotation(logMessage = "创建支付单,查询支付配置")
    @GetMapping("/getPayConfig")
    public BaseResponse<String> getPayConfig(@LogParams @RequestParam("partnerId") String partnerId, @RequestParam("appId") String appId) {
        String payConfig = payService.getPayConfig(partnerId, appId);
        return ResponseUtil.success(payConfig);
    }

    /**
     * 创建支付单,查询超时时间
     */
    @ApiAnnotation(logMessage = "创建支付单,查询超时时间")
    @GetMapping("/getPayTimeout")
    public BaseResponse<String> getPayTimeout(@LogParams @RequestParam("partnerId") String partnerId) {
        String partnerPayOvertime = payService.getPartnerPayOvertime(partnerId);
        return ResponseUtil.success(partnerPayOvertime);
    }

    /**
     * 创建支付单,查询payCode
     */
    @ApiAnnotation(logMessage = "创建支付单,查询payCode")
    @GetMapping("/getPayCodeByChanel")
    public BaseResponse<String> getPayCodeByChanel(@LogParams @RequestParam("appId") String appId,
                                                   @RequestParam("storeId") String storeId,
                                                   @RequestParam(value = "channel", required = false) String channel) {

        String payCodeByCondition = payService.getPayCodeByCondition(appId, storeId, channel);
        return ResponseUtil.success(payCodeByCondition);
    }

    /**
     * 创建订单,死信队列
     */
    @ApiAnnotation(logMessage = "创建订单,死信队列")
    @PostMapping("/deadLetterQueue")
    public BaseResponse deadLetterQueue(@LogParams @RequestBody PutDeadLetterVo putDeadLetterVo) {
        payService.putDelMq(putDeadLetterVo.getPartnerId(), putDeadLetterVo.getStoreId(), putDeadLetterVo.getFmId(), putDeadLetterVo.getOrderId(), putDeadLetterVo.getPayChanelType());
        return ResponseUtil.success();
    }

}
