package com.multictrl.modules.business.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;

/**
 * influxdb操作
 *
 * @author Sdy
 * @since 1.0.0 2026/5/3
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@Schema(name = "飞机上报数据")
@Measurement(name = "uav_osd")
public class UavReport {

    @Schema(description = "主控sn")
    @Column(tag = true)
    private String dockSn;

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

    @Schema(description = "水平避障状态")
    @Column
    private Integer obstacle_avoidance_horizon;

    @Schema(description = "上视避障状态")
    @Column
    private Integer obstacle_avoidance_upside;

    @Schema(description = "下视避障状态")
    @Column
    private Integer obstacle_avoidance_downside;

    @Schema(description = "是否接近限飞区 {\"0\":\"未达到限飞区\",\"1\":\"接近限飞区\"}")
    @Column
    private Integer is_near_area_limit;

    @Schema(description = "是否接近设定的限制高度 {\"0\":\"未达到设定的限制高度\",\"1\":\"接近设定的限制高度\"}")
    @Column
    private Integer is_near_height_limit;

    @Schema(description = "云台俯仰轴角度")
    @Column
    private Double gimbal_pitch;

    @Schema(description = "云台横滚轴角度")
    @Column
    private Double gimbal_roll;

    @Schema(description = "云台偏航轴角度")
    @Column
    private Double gimbal_yaw;

    @Schema(description = "负载索引，格式为 {type-subtype-gimbalindex}")
    @Column
    private String payload_index;

    @Schema(description = "变焦倍数")
    @Column
    private Double zoom_factor;

    @Schema(description = "航迹 ID")
    @Column
    private String track_id;

    @Schema(description = "是否收敛 {\"0\":\"未开始\",\"1\":\"收敛中\",\"2\":\"收敛成功\",\"3\":\"收敛失败\"}")
    @Column
    private Integer position_state_is_fixed;

    @Schema(description = "搜星档位 {\"1\":\"1档\",\"2\":\"2档\",\"3\":\"3档\",\"4\":\"4档\",\"5\":\"5档\",\"10\":\"RTK fixed\"}\t")
    @Column
    private Integer position_state_is_quality;

    @Schema(description = "GPS 搜星数量")
    @Column
    private Integer position_state_is_gps_number;

    @Schema(description = "RTK 搜星数量")
    @Column
    private Integer position_state_is_rtk_number;

    @Schema(description = "电池的总剩余电量")
    @Column
    private Integer battery_capacity_percent;

    @Schema(description = "剩余飞行时间")
    @Column
    private Integer battery_remain_flight_time;

    @Schema(description = "返航所需电量百分比")
    @Column
    private Integer battery_return_home_power;

    @Schema(description = "强制降落电量百分比")
    @Column
    private Integer battery_landing_power;

    @Schema(description = "A电池剩余电量")
    @Column
    private Integer battery_capacity_percent_a;

    @Schema(description = "B电池剩余电量")
    @Column
    private Integer battery_capacity_percent_b;

    @Schema(description = "当前风向 {\"1\":\"正北\",\"2\":\"东北\",\"3\":\"东\",\"4\":\"东南\",\"5\":\"南\",\"6\":\"西南\",\"7\":\"西\",\"8\":\"西北\"}\t")
    @Column
    private Integer wind_direction;

    @Schema(description = "风速 {\"unit_name\":\"0.1 米每秒 / m/s\"}")
    @Column
    private Double wind_speed;

    @Schema(description = "距离 Home 点的距离")
    @Column
    private Double home_distance;

   /* @Schema(description = "Home 点纬度")
    @Column
    private Double home_latitude;

    @Schema(description = "Home 点经度")
    @Column
    private Double home_longitude;*/

    @Schema(description = "偏航轴角度")
    @Column
    private Integer attitude_head;

    @Schema(description = "横滚轴角度")
    @Column
    private Double attitude_roll;

    @Schema(description = "俯仰轴角度")
    @Column
    private Double attitude_pitch;

    @Schema(description = "相对起飞点高度")
    @Column
    private Double elevation;

    @Schema(description = "绝对高度")
    @Column
    private Double height;

    @Schema(description = "当前位置纬度")
    @Column
    private Double latitude;

    @Schema(description = "当前位置经度")
    @Column
    private Double longitude;

    @Schema(description = "垂直速度")
    @Column
    private Double vertical_speed;

    @Schema(description = "水平速度")
    @Column
    private Double horizontal_speed;

    /**
     * 时间字符串
     */
    private String timeStr;

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