package com.zd.system.api.laboratory.domain.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.zd.common.core.enums.SenseType;
import com.zd.common.core.domain.hazard.BaseHardware;
import com.zd.common.core.domain.hazard.HardwareType;
import com.zd.common.core.utils.SpringUtils;
import com.zd.system.api.laboratory.domain.SensorFunctionStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @Author: zhoupan
 * @Date: 2021/09/16/14:51
 * @Description:
 */
@ApiModel("传感器VO")
public class SenseValVO extends BaseHardware {


    @ApiModelProperty("传感器类型")
    SenseType senseType;
    @Deprecated
    @ApiModelProperty("值")
    String val;

    /**
     * 解决传感器多功能问题
     */
    @ApiModelProperty("传感器功能列表")
    List<SensorFunctionStatus> sensorFunctionStatusesList;


    /**
     * 如果是单功能则有值
     * @return
     */
    public SensorFunctionStatus getSensorFunctionStatuses() {

        if(CollUtil.isNotEmpty(sensorFunctionStatusesList)&&sensorFunctionStatusesList.size()==1) return sensorFunctionStatusesList.get(0);
        return null;
    }


    public List<SensorFunctionStatus> getSensorFunctionStatusesList() {
        return sensorFunctionStatusesList;
    }

    public void setSensorFunctionStatusesList(List<SensorFunctionStatus> sensorFunctionStatusesList) {
        this.sensorFunctionStatusesList = sensorFunctionStatusesList;
    }

    /**
     * 单功能
     */



    public SenseType getSenseType() {
        return senseType;
    }

    public void setSenseType(SenseType senseType) {
        this.senseType = senseType;
    }

    public String getVal() {
        if (SpringUtils.getActiveProfile().equals("dev")) {
            return StrUtil.format("{}{}", RandomUtil.randomInt(10, 100),Optional.ofNullable(senseType).map(a->a.getUnit()).orElse("") );
        }
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

    /**
     * 设备类型
     *
     * @return
     */
    @Override
    protected HardwareType hardwareType() {

        return senseType;
    }
}
