package com.multictrl.modules.business.q20.influxdb;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import com.multictrl.common.utils.DateUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

/**
 * Q20设备电池数据 InfluxDB记录
 *
 * @author 938693313@qq.com
 * @since 1.0.0 2026/5/12
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@Schema(name = "Q20设备电池上报数据")
@Measurement(name = "q20_battery")
public class Q20BatteryReport {

    @Schema(description = "设备SN")
    @Column(tag = true)
    private String deviceSn;

    @Schema(description = "电池ID")
    @Column(tag = true)
    private String battery_id;

    @Schema(description = "架次号")
    @Column(tag = true)
    private String order_id;

    @Schema(hidden = true)
    @Column(timestamp = true)
    @JsonProperty("_time")
    private Instant time;

    @Schema(description = "满电容量，单位mAh")
    @Column
    private Integer full_charge_capacity;

    @Schema(description = "剩余电量，单位%")
    @Column
    private Float charge_remaining;

    @Schema(description = "电压，单位mV")
    @Column
    private Integer voltage;

    @Schema(description = "电流，单位mA，放电为正充电为负")
    @Column
    private Integer current;

    @Schema(description = "低电量警告阈值，单位%")
    @Column
    private Integer low_volt_warn_value;

    @Schema(description = "电池状态：0异常/1开机/2充电中/3需保养")
    @Column
    private Integer status;

    @Schema(description = "电池温度，单位℃")
    @Column
    private Float temperature;

    @Schema(description = "充放电循环次数")
    @Column
    private Integer cycle_index;

    @Schema(description = "本次飞行时长，单位秒")
    @Column
    private Long time_flying;

    @Schema(description = "剩余可飞时间，单位秒")
    @Column
    private Integer time_remaining;

    @Schema(description = "剩余充电时间，单位秒")
    @Column
    private Integer charge_time_remaining;

    @Schema(description = "电池健康度，单位%")
    @Column
    private Integer health;

    @Schema(description = "电池标志位")
    @Column
    private Integer flags;

    @Schema(description = "电池唯一标识")
    @Column
    private String uid;

    @Schema(description = "电池固件版本")
    @Column
    private String version;

    private String timeStr;

    public void setTime(Instant time) {
        this.time = time;
        this.timeStr = DateUtils.utcToTime(time);
    }
}
