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设备OSD基础遥测数据 InfluxDB记录
 *
 * @author 938693313@qq.com
 * @since 1.0.0 2026/5/12
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@Schema(name = "Q20设备OSD上报数据")
@Measurement(name = "q20_osd")
public class Q20OsdReport {

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

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

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

    @Schema(description = "位置经度，WGS84，精确到小数点后7位")
    @Column
    private Double longitude;

    @Schema(description = "位置纬度，WGS84，精确到小数点后7位")
    @Column
    private Double latitude;

    @Schema(description = "相对起飞点高度，单位m")
    @Column
    private Float height;

    @Schema(description = "海拔高度，单位m")
    @Column
    private Float altitude;

    @Schema(description = "垂直飞行速度，单位m/s，向上为负向下为正")
    @Column
    private Float vs;

    @Schema(description = "水平飞行速度（对地速度），单位m/s")
    @Column
    private Float gs;

    @Schema(description = "航向，取值范围[0,360]，正北为0顺时针递增，单位°")
    @Column
    private Float heading;

    @Schema(description = "俯仰角，取值范围[-90,90]，仰为正俯为负，单位°")
    @Column
    private Float pitch;

    @Schema(description = "横滚角，取值范围[-90,90]，向左为正向右为负，单位°")
    @Column
    private Float roll;

    @Schema(description = "电池容量百分比，多电池为融合总电量，单位%")
    @Column
    private Integer battery;

    @Schema(description = "电池电压，多电池为平均电压，单位V")
    @Column
    private Integer voltage;

    @Schema(description = "飞行模式：MANUAL/ALTCTL/POSCTL/AUTO.MISSION/AUTO.RTL/AUTO.LAND等")
    @Column
    private String mode;

    @Schema(description = "是否飞行中：1飞行中，0非飞行中")
    @Column
    private Integer flying;

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

    @Schema(description = "飞行里程，单位m")
    @Column
    private Float fly_distance;

    @Schema(description = "返航点是否已设置：1已设置，0未设置")
    @Column
    private Integer home_set;

    @Schema(description = "距离返航点距离，单位m")
    @Column
    private Float home_distance;

    @Schema(description = "返航点相对高度，单位m")
    @Column
    private Float home_altitude;

    @Schema(description = "返航点纬度")
    @Column
    private Float home_latitude;

    @Schema(description = "返航点经度")
    @Column
    private Float home_longitude;

    @Schema(description = "安全开关：1已启用，0未启用")
    @Column
    private Integer state_safe_enabled;

    @Schema(description = "RTK是否启用：1已启用，0未启用")
    @Column
    private Integer state_rtk_enabled;

    @Schema(description = "RTCM是否连接：1已连接，0未连接")
    @Column
    private Integer state_rtk_connected;

    @Schema(description = "遥控是否连接：1已连接，0未连接")
    @Column
    private Integer state_rc_connected;

    @Schema(description = "避障是否开启：1已启用，0未启用")
    @Column
    private Integer state_obs_enabled;

    @Schema(description = "加速度计校准状态：1已校准，0未校准")
    @Column
    private Integer state_accel_cal;

    @Schema(description = "陀螺仪校准状态：1已校准，0未校准")
    @Column
    private Integer state_gyro_cal;

    @Schema(description = "水平校准状态：1已校准，0未校准")
    @Column
    private Integer state_hor_cal;

    @Schema(description = "指南针校准状态：1已校准，0未校准")
    @Column
    private Integer state_mag_cal;

    @Schema(description = "FPV推流状态：1开启，0关闭")
    @Column
    private Integer state_fpv_live;

    @Schema(description = "云台推流状态：0关闭，1主码流，2子码流")
    @Column
    private Integer state_stream_live;

    private String timeStr;

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