package cn.minbb.iot.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "device_data")
@NoArgsConstructor
public class DeviceData implements Serializable {

    @Getter
    @Setter
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, columnDefinition = "INT COMMENT '设备数据实体ID'")
    private Long id;

    @Getter
    @Setter
    @Column(name = "temperature", columnDefinition = "FLOAT COMMENT '温度'")
    private Float temperature;

    @Getter
    @Setter
    @Column(name = "pressure", columnDefinition = "FLOAT COMMENT '压强'")
    private Float pressure;

    @Getter
    @Setter
    @Column(name = "altitude", columnDefinition = "FLOAT COMMENT '海拔'")
    private Float altitude;

    @Getter
    @Setter
    @Column(name = "longitude", columnDefinition = "VARCHAR(16) COMMENT '经度'")
    private String longitude;

    @Getter
    @Setter
    @Column(name = "latitude", columnDefinition = "VARCHAR(16) COMMENT '纬度'")
    private String latitude;

    @Getter
    @Setter
    @Column(name = "speed", columnDefinition = "FLOAT COMMENT '速度'")
    private Float speed;

    @Getter
    @Setter
    @Column(name = "gps_time", columnDefinition = "FLOAT COMMENT 'GPS时间'")
    private Float gpsTime;

    @Getter
    @Setter
    @Column(name = "bei_jing_time", columnDefinition = "INTEGER COMMENT '北京时间'")
    private Integer beiJingTime;

    @Getter
    @Setter
    @Column(name = "remark", columnDefinition = "VARCHAR(64) COMMENT '备注'")
    private String remark;

    @Getter
    @Setter
    @Column(name = "device_id", nullable = false, columnDefinition = "BIGINT COMMENT '关联设备'")
    private Long deviceId;

    @Getter
    @Setter
    @Column(name = "created_at", columnDefinition = "DATETIME COMMENT '创建时间'")
    @CreationTimestamp
    private Date createdAt;

    @Version
    @Column(name = "version", columnDefinition = "BIGINT COMMENT '版本号'")
    public Long version;

    public DeviceData(String longitude, String latitude, String remark) {
        this.longitude = longitude;
        this.latitude = latitude;
        this.remark = remark;
    }
}
