package com.gyee.dataadapter.entity;

import com.fasterxml.jackson.annotation.*;
import com.gyee.dataadapter.dao.TsDataType;

import java.util.Date;

/**
 * 测点数据
 */
public class PointData {
    /**
     * 时间戳
     */
    private long ts;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date time;
    private String tagName;
    /**
     * 数据
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
//    @JsonSetter(nulls = Nulls.SKIP)
    private Double doubleValue;
    /**
     * Boolean 数据
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
//    @JsonSetter(nulls = Nulls.SKIP)
    private Boolean booleanValue;
    @JsonInclude(JsonInclude.Include.NON_NULL)
//    @JsonSetter(nulls = Nulls.SKIP)
    private Long longValue;

    public PointData() {
    }

    public PointData(Date time, double doubleValue) {
        this.time = time;
        this.doubleValue = doubleValue;
    }

    public long getTs() {
        if (ts == 0 && time != null) {
            return time.getTime();
        }
        return ts;
    }

    public void setTs(long ts) {
        this.ts = ts;
    }

    @JsonIgnore
    public TsDataType getDataType() {
        if (booleanValue != null && booleanValue) {
            return TsDataType.BOOLEAN;
        } else if (longValue != null && longValue != 0) {
            return TsDataType.LONG;
        }
        return TsDataType.DOUBLE;
    }

    public Boolean getBooleanValue() {
        return booleanValue;
    }

    public Boolean isBooleanValue() {
        return booleanValue;
    }

    public void setBooleanValue(boolean booleanValue) {
        this.booleanValue = booleanValue;
    }

    public Long getLongValue() {
        return longValue;
    }

    public void setLongValue(long longValue) {
        this.longValue = longValue;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    public Double getDoubleValue() {
        return doubleValue;
    }

    public void setDoubleValue(double doubleValue) {
        this.doubleValue = doubleValue;
    }

    @JsonIgnore
    public Double getValue() {
        if (booleanValue != null && booleanValue) {
            return 1.0;
        } else if (longValue != null && longValue != 0) {
            doubleValue = Double.valueOf(longValue);
        }
        return doubleValue;
    }

}
