package com.inspect.partrolresult.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.inspect.base.core.utils.StringUtils;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
public class ResultValue implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long lineId;
    private String areaName;
    private String deviceName;
    @JsonProperty(value = "patroldeviceName")
    private String patrolDeviceName;
    @JsonProperty(value = "patrolpointName")
    private String patrolPointName;
    private String value;
    private String createTime;

    public String formatValue(String args) {
        if(StringUtils.isEmpty(args)) {
            return StringUtils.EMPTY;
        }
        String pattern = "(\\d+(\\.\\d+)?)";
        String valueOnlyPrecise = args.replaceAll(".*?(" + pattern + ").*", "$1");
        if(valueOnlyPrecise.startsWith(".")) {
            valueOnlyPrecise = "0" + valueOnlyPrecise;
        }

        if(valueOnlyPrecise.equals("0.0")) {
            valueOnlyPrecise = "0";
        }

        if(args.startsWith("-")) {
            valueOnlyPrecise = "-" + valueOnlyPrecise;
        }

        return valueOnlyPrecise;
    }

    @Override
    public String toString() {
        return "ResultValue{" +
                "lineId=" + lineId +
                ", areaName='" + areaName + '\'' +
                ", deviceName='" + deviceName + '\'' +
                ", patrolDeviceName='" + patrolDeviceName + '\'' +
                ", patrolPointName='" + patrolPointName + '\'' +
                ", value='" + value + '\'' +
                ", createTime='" + createTime + '\'' +
                '}';
    }
}
