package com.gyee.runeconomy.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gyee.runeconomy.config.UniformCode;

import java.io.Serializable;

/**
 * 风机
 */
public class WindturbineInfo implements Serializable {
    /**
     * ID
     */
    private String id;
    /**
     * Code
     */
    private String code;
    /**
     * 型号
     */
    private String modelId;
    /**
     * 风机期次信息
     */
    private String projectId;
    /**
     * 场站信息
     */
    private String stationId;
    /**
     * 场站名称
     */
    private String stationName;
    /**
     * 线路信息
     */
    private String lineId;
    /**
     * 最小切入风速
     */
    private double minimumWindSpeed = 3.5;
    /**
     * 装机容量
     */
    private double powerProduction;
    /**
     * 编号
     */
    private int index;
    /**
     * 状态
     */
    @UniformCode("${windturbine.status:FJZT8}")
    private TagInfo status;
    /**
     * 转速
     */
    @UniformCode("AI128")
    private TagInfo rollSpeed;
    /**
     * 功率
     */
    @UniformCode("AI130")
    private TagInfo power;
    /**
     * 风速
     */
    @UniformCode("AI022")
    private TagInfo windSpeed;
    /**
     * 挂牌类型
     */
    @UniformCode("${windturbine.lock_type:XDSL}")
    private TagInfo lockType;
    /**
     * 理论功率
     */
    @UniformCode("LLGL")
    private TagInfo theoreticalPower;
    /**
     * 5分钟平均风速
     */
    @UniformCode("YDPJFS5M")
    private TagInfo averageWindSpeed5;
    /**
     * 故障状态
     */
    @UniformCode("GZZT")
    private TagInfo faultStatus;
    /**
     * 资源等级
     */
    @UniformCode("ZYZS")
    private TagInfo resourceLevel;

    /**
     * 是否为紧急报警
     */
    private boolean isEmergencyAlarm = false;
    /**
     * 风机评分
     */
    @UniformCode("JKZS")
    private TagInfo score;
    /**
     * 欠发状态
     */
    @UniformCode("${windturbine.undelivered:RSSQFZT}")
    private TagInfo undeliveredStatus;

    /**
     * 解缆状态
     */
    @UniformCode("${windturbine.unhooking:DI012}")
    private TagInfo unhooking;
    /**
     * 欠发状态
     */
    @UniformCode("${windturbine.wind_trends:FSQS}")
    private TagInfo windTrends;

    /**
     * 是否状态异常（故障状态为true，但是风速可启动）
     */
    private boolean abnormalState;

    /**
     * 风机控制指令
     */
//    private Map<OperateStyle, CmdInfo> cmdInfos;

    public String getId() {
        return id;
    }

    public String getWindturbineId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
        if (id == null) {
            return;
        }
        final String[] ss = id.split("_");
        if (ss.length != 2) {
            return;
        }
        try {
            index = Integer.valueOf(ss[1]);
        } catch (Exception e) {
        }
    }

    public int getIndex() {
        return index;
    }

    public String getModelId() {
        return modelId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public double getStatus() {
        if (this.status == null) {
            this.status = new TagInfo();
        }
        return status.getValue();
    }

    public TagInfo getStatusInfo() {
        if (this.status == null) {
            this.status = new TagInfo();
        }
        return this.status;
    }

    public void setStatus(double status) {
        if (this.status == null) {
            this.status = new TagInfo();
        }
        this.status.setValue(status);
    }

    /**
     * 状态时间
     *
     * @return
     */
    public long getTs() {

        if (this.status == null) {
            this.status = new TagInfo();
        }
        return status.getTimestamp();
    }

    public String getStationId() {
        return stationId;
    }

    public void setStationId(String stationId) {
        this.stationId = stationId;
    }

    public String getStationName() {
        return stationName;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public double getRollSpeed() {
        if (this.rollSpeed == null) {
            this.rollSpeed = new TagInfo();
        }
        return rollSpeed.getValue();
    }

    public void setRollSpeed(double rollSpeed) {
        if (this.rollSpeed == null) {
            this.rollSpeed = new TagInfo();
        }
        this.rollSpeed.setValue(rollSpeed);
    }

    public double getPower() {
        if (this.power == null) {
            this.power = new TagInfo();
        }
        return power.getValue();
    }

    public void setPower(double power) {
        if (this.power == null) {
            this.power = new TagInfo();
        }
        this.power.setValue(power);
    }

    public double getWindSpeed() {
        if (this.windSpeed == null) {
            this.windSpeed = new TagInfo();
        }
        return windSpeed.getValue();
    }

    public void setWindSpeed(double windSpeed) {
        if (this.windSpeed == null) {
            this.windSpeed = new TagInfo();
        }
        this.windSpeed.setValue(windSpeed);
    }

    /**
     * 获取风速标签
     */
    @JsonIgnore
    public String getWindSpeedTag() {
        if (this.windSpeed == null) {
            this.windSpeed = new TagInfo();
        }
        return windSpeed.getTag();
    }

    public void setStatusTag(String tag) {
        if (status == null) {
            status = new TagInfo();
        }
        this.status.setTag(tag);
    }

    public void setRollSpeedTag(String tag) {
        if (rollSpeed == null) {
            rollSpeed = new TagInfo();
        }
        this.rollSpeed.setTag(tag);
    }

    public void setPowerTag(String tag) {
        if (power == null) {
            power = new TagInfo();
        }
        this.power.setTag(tag);
    }

    public void setWindSpeedTag(String tag) {
        if (windSpeed == null) {
            windSpeed = new TagInfo();
        }
        this.windSpeed.setTag(tag);
    }

    public double getLockType() {
        if (this.lockType == null) {
            this.lockType = new TagInfo();
        }
        return lockType.getValue();
    }

    public double getLockValue() {
        return getLockType();
    }

    public void setLockType(double lockType) {
        if (this.lockType == null) {
            this.lockType = new TagInfo();
        }
        this.lockType.setValue(lockType);
    }

    public void setLockTypeTag(String tag) {
        if (lockType == null) {
            lockType = new TagInfo();
        }
        this.lockType.setTag(tag);
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public double getTheoreticalPower() {
        if (theoreticalPower == null) {
            theoreticalPower = new TagInfo();
        }
        return theoreticalPower.getValue();
    }

    public void setTheoreticalPower(double theoreticalPower) {
        if (this.theoreticalPower == null) {
            this.theoreticalPower = new TagInfo();
        }
        this.theoreticalPower.setValue(theoreticalPower);
    }

    public double getMinimumWindSpeed() {
        if (minimumWindSpeed < 3) {
            return 3.5;
        }
        return minimumWindSpeed;
    }

    public void setMinimumWindSpeed(double minimumWindSpeed) {
        this.minimumWindSpeed = minimumWindSpeed;
    }

    public double getAverageWindSpeed5() {
        if (averageWindSpeed5 == null) {
            averageWindSpeed5 = new TagInfo();
        }
        return averageWindSpeed5.getValue();
    }

    public void setAverageWindSpeed5(double averageWindSpeed5) {
        if (this.averageWindSpeed5 == null) {
            this.averageWindSpeed5 = new TagInfo();
        }
        this.averageWindSpeed5.setValue(averageWindSpeed5);
    }

    @JsonIgnore
    public String getAverageWindSpeed5Tag() {
        if (averageWindSpeed5 == null) {
            averageWindSpeed5 = new TagInfo();
        }
        return averageWindSpeed5.getTag();
    }

    public boolean getFaultStatus() {
        if (faultStatus == null) {
            faultStatus = new TagInfo(1);
        }
        return faultStatus.getValue() == 1;
    }

    public void setFaultStatus(boolean faultStatus) {
        if (this.faultStatus == null) {
            this.faultStatus = new TagInfo();
        }
        this.faultStatus.setValue(faultStatus ? 1 : 0);
    }

    public double getResourceLevel() {
        if (this.resourceLevel == null) {
            this.resourceLevel = new TagInfo();
        }
        return resourceLevel.getValue();
    }

    public void setResourceLevel(double resourceLevel) {
        if (this.resourceLevel == null) {
            this.resourceLevel = new TagInfo();
        }
        this.resourceLevel.setValue(resourceLevel);
    }

    /**
     * 获取风机潜力
     */
    public double getPotential() {
        double potential = theoreticalPower.getValue() - power.getValue();
        potential = potential < 0 ? 0 : potential;
        return potential;
    }

    /**
     * 获取风能利用率
     *
     * @return 风能利用率
     */
    public double getWindEnergyUtilisation() {
        return getPower() / getTheoreticalPower();
    }

    public boolean isEmergencyAlarm() {
        return isEmergencyAlarm;
    }

    public void setEmergencyAlarm(boolean emergencyAlarm) {
        isEmergencyAlarm = emergencyAlarm;
    }

    public double getScore() {
        if (this.score == null) {
            this.score = new TagInfo();
        }
        return score.getValue();
    }

    public void setScore(double score) {
        if (this.score == null) {
            this.score = new TagInfo();
        }
        this.score.setValue(score);
    }

    public String getLineId() {
        return lineId;
    }

    public void setLineId(String lineId) {
        this.lineId = lineId;
    }

    @JsonIgnore
    public String getLockTypeTag() {
        if (this.lockType == null) {
            this.lockType = new TagInfo();
        }
        return this.lockType.getTag();
    }

    @JsonIgnore
    public String getStatusTag() {
        if (this.status == null) {
            this.status = new TagInfo();
        }
        return this.status.getTag();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public double getPowerProduction() {
        return powerProduction;
    }

    public void setPowerProduction(double powerProduction) {
        this.powerProduction = powerProduction;
    }

    public boolean getAbnormalState() {
        return abnormalState;
    }

    public void setAbnormalState(boolean abnormalState) {
        this.abnormalState = abnormalState;
    }

    public double getUndeliveredStatus() {
        if (this.undeliveredStatus == null) {
            this.undeliveredStatus = new TagInfo();
        }
        return undeliveredStatus.getValue();
    }

    public void setUndeliveredStatus(double undeliveredStatus) {
        if (this.undeliveredStatus == null) {
            this.undeliveredStatus = new TagInfo();
        }
        this.undeliveredStatus.setValue(undeliveredStatus);
    }

    public TagInfo getUnhooking() {
        if (unhooking == null) {
            unhooking = new TagInfo();
        }
        return unhooking;
    }

    public void setUnhooking(TagInfo unhooking) {
        this.unhooking = unhooking;
    }

    public TagInfo getWindTrends() {
        if (windTrends == null) {
            windTrends = new TagInfo();
        }
        return windTrends;
    }

    public void setWindTrends(TagInfo windTrends) {
        this.windTrends = windTrends;
    }

//    @JsonIgnore
//    public Map<OperateStyle, CmdInfo> getCmdInfos() {
//        if (cmdInfos == null) {
//            cmdInfos = new HashMap<>();
//        }
//        return cmdInfos;
//    }
}
