package cn.pluss.platform.alidevice;

import cn.pluss.platform.entity.DeviceStock;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;


/**
 *
 *阿里扫码设备状态返回参数封装
 *@author: bzg
 *@time: 2021/12/22 11:39
 */
@Data
public class AliScanCodeDeviceStatus {


    /**
     * 绑定状态值
     * @date: 2021/12/22 11:47
     */
    private Integer status;

    private String store_name;

    private String merchant_name;

    private String mercId;


    @Getter
    @AllArgsConstructor
    enum DeviceStatusEnum{
        SUCCESS(1,"已绑定"),
        FAIL(0,"未绑定");

        private Integer code;

        private String name;
    }

    /**
     * 获取设备绑定状态
     * @date: 2021/12/22 13:45
     * @param deviceStock:
     * @return java.lang.Integer
     */
    public static RespDeviceEntity getAliDeviceStatusV1(DeviceStock deviceStock){
        if(deviceStock == null || !"3".equals(deviceStock.getStatus())){
            return RespDeviceEntity.fail("设备号有误或设备状态异常",DeviceStatusEnum.FAIL.code);
        }
        return RespDeviceEntity.success("获取成功", DeviceStatusEnum.SUCCESS.code);
    }

    public static RespDeviceEntity getAliDeviceStatusV2(DeviceStock deviceStock) {
        AliScanCodeDeviceStatus deviceStatus = new AliScanCodeDeviceStatus();
        RespDeviceEntity v1 = getAliDeviceStatusV1(deviceStock);
        deviceStatus.setStatus((Integer) v1.getData());
        if(DeviceStatusEnum.SUCCESS.getCode().equals(deviceStatus.getStatus())){
            deviceStatus.setStore_name(deviceStock.getActMercName());
            deviceStatus.setMerchant_name(deviceStock.getActMercName());
            deviceStatus.setMercId(deviceStock.getActMercId());
            v1.setData(deviceStatus);
        }
        return v1;
    }
}
