package vip.xiaonuo.coldchain.core.bean.influxdb;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.github.jfcloud.influxdb.model.JfcloudInFluxEntity;
import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import vip.xiaonuo.coldchain.core.config.JfcloudColdChainConstants;
import vip.xiaonuo.coldchain.core.service.dataprocess.model.PowerEnum;
import vip.xiaonuo.coldchain.modular.app.param.DoubleNullToDashSerializer;
import vip.xiaonuo.coldchain.modular.app.param.FloatNullToDashSerializer;

import java.time.Year;

/**
 * SensorData类，用于表示传感器数据，继承自JfcloudInFluxEntity。
 * 使用反射将FluxRecord映射到此类的属性。
 */
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Measurement(name = JfcloudColdChainConstants.INFLUXDB_DEFAULT_MEASUREMENT_NAME)
@Slf4j
public class SensorData extends JfcloudInFluxEntity {
    @Column(name = "temperature")
    @JsonSerialize(using = FloatNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float temperature;

    @Column(name = "humidity")
    @JsonSerialize(using = FloatNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float humidity;

    @Column(name = "co2")
    @JsonSerialize(using = FloatNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float co2;

    @Column(name = "battery")
    @JsonSerialize(using = FloatNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Float battery;

    @Column(name = "plugInStatus")
    private String plugInStatus = PowerEnum.AC.getCode();

    @Column(name = "location")
    private String location;

    @Column(name = "longitude")
    @JsonSerialize(using = DoubleNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Double lng;

    @Column(name = "latitude")
    @JsonSerialize(using = DoubleNullToDashSerializer.class)  // 使用自定义序列化器
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "#.00")
    private Double lat;

    @Column(name = "device_id", tag = true)
    private String deviceId;

    @Column(name = "roads", tag = true)
    private Integer roads = 1;

    @Column(name = "model_name", tag = true)
    private String modelName;

    @Column(name = "year", tag = true)
    private Integer year = Year.now().getValue();

    @Column(name = "create_time")
    private String createTime;
    /**
     * 实时数据0  历史数据1
     */
    @Column(name = "type")
    private Integer type = DataType.NEW.getCode();

}
