package cn.pluss.platform.controller.home;

import cn.pluss.platform.ali.device.AliDeviceService;
import cn.pluss.platform.alidevice.AliScanCodeDevicePayEntity;
import cn.pluss.platform.alidevice.AliScanCodeDevicePayEnum;
import cn.pluss.platform.alidevice.RespDeviceEntity;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 *阿里云设备管理类
 *@author: bzg
 *@time: 2021/12/22 11:26
 */
@RestController
@RequestMapping(value = "aliyun/device")
public class AliYunDeviceController {

    @Setter(onMethod_ = {@Autowired, @Qualifier("aliScanCodeDeviceService")})
    private AliDeviceService aliScanCodeDeviceService;


    /**
     * 反扫阿里云扫码王设备支付接口
     * @date: 2021/12/27 11:35
     * @param payEntity:
     * @return cn.pluss.platform.alidevice.RespDeviceEntity
     */
    @RequestMapping(value = "/pay/barcode",method = RequestMethod.POST)
    public RespDeviceEntity payBarCode(@RequestBody AliScanCodeDevicePayEntity payEntity){
        return aliScanCodeDeviceService.orderPay(payEntity, AliScanCodeDevicePayEnum.BARCODE.getCode());
    }

    /**
     * 主扫阿里云扫码王设备支付接口
     * @date: 2021/12/27 11:36
     * @param payEntity:
     * @return cn.pluss.platform.alidevice.RespDeviceEntity
     */
    @RequestMapping(value = "/pay/qrcode",method = RequestMethod.POST)
    public RespDeviceEntity payQrCode(@RequestBody AliScanCodeDevicePayEntity payEntity){
        return aliScanCodeDeviceService.orderPay(payEntity, AliScanCodeDevicePayEnum.QRCODE.getCode());
    }
    /**
     * 阿里云设备扫码王订单查询接口
     * @date: 2021/12/27 11:36
     * @param payEntity:
     * @return cn.pluss.platform.alidevice.RespDeviceEntity
     */
    @RequestMapping(value = "/order/query",method = RequestMethod.POST)
    public RespDeviceEntity orderQuery(@RequestBody AliScanCodeDevicePayEntity payEntity){
        return aliScanCodeDeviceService.orderQuery(payEntity.getTrace());
    }

    /**
     * 获取阿里云云设备状态接口V1
     * @date: 2021/12/27 11:37
     * @return java.lang.Integer
     */
    @RequestMapping(value = "/status/v1",method = RequestMethod.POST)
    public RespDeviceEntity getStatusV1(@RequestBody AliScanCodeDevicePayEntity payEntity){
        return aliScanCodeDeviceService.getDeviceStatusV1(payEntity.getCode());
    }

    /**
     * 获取阿里云扫码王设备状态接口V2
     * @date: 2021/12/27 11:37
     * @param payEntity:
     * @return cn.pluss.platform.alidevice.AliScanCodeDeviceStatus
     */
    @RequestMapping(value = "/status/v2",method = RequestMethod.POST)
    public RespDeviceEntity getStatusV2(@RequestBody AliScanCodeDevicePayEntity payEntity){
        return aliScanCodeDeviceService.getDeviceStatusV2(payEntity.getCode());
    }

//    /**
//     * 设备绑定接口 测试
//     * @date: 2021/12/27 14:45
//     * @param deviceNo:
//     * @return cn.pluss.platform.alidevice.RespDeviceEntity
//     */
//    @RequestMapping(value = "/bind/{deviceNo}",method = RequestMethod.POST)
//    @ResponseBody
//    public Result<Object> payBarCode(@PathVariable("deviceNo") String deviceNo){
//        return aliScanCodeDeviceService.bindDevice(deviceNo,"1791");
//    }
}
