package com.qaup.collision.pathconflict.model.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.time.LocalDateTime;

/**
 * 冲突预警告警记录实体类
 * 对应 conflict_alert_logs 表，记录发送的所有预警和告警消息
 * 
 * @author AI Assistant
 * @version 1.0
 * @since 2025-01-17
 */
@Entity
@Table(name = "conflict_alert_logs", indexes = {
    @Index(name = "idx_conflict_alerts_type", columnList = "alert_type"),
    @Index(name = "idx_conflict_alerts_level", columnList = "alert_level"),
    @Index(name = "idx_conflict_alerts_time", columnList = "alert_time DESC")
})
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ConflictAlertLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 告警类型：CONFLICT_WARNING, CONFLICT_ALERT
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "alert_type", nullable = false, length = 50) // 增加长度以适应新类型
    private AlertType alertType;

    /**
     * 告警级别：WARNING, CRITICAL, EMERGENCY
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "alert_level", nullable = false, length = 20)
    private AlertLevel alertLevel;

    /**
     * 告警消息内容
     */
    @Column(name = "alert_message", nullable = false, columnDefinition = "TEXT")
    private String alertMessage;

    /**
     * 对象1距离冲突点距离 (米)
     */
    @Column(name = "object1_distance")
    private Double object1Distance;

    /**
     * 对象2距离冲突点距离 (米)
     */
    @Column(name = "object2_distance")
    private Double object2Distance;

    /**
     * 两对象之间最小距离 (米)
     */
    @Column(name = "minimum_distance")
    private Double minimumDistance;

    /**
     * 告警时间
     */
    @Column(name = "alert_time")
    private LocalDateTime alertTime;

    /**
     * 告警类型枚举 - 用于区分告警的来源或类别
     */
    public enum AlertType {
        CONFLICT_WARNING, // 冲突预警
        CONFLICT_ALERT    // 冲突告警
    }

    /**
     * 告警级别枚举 - 用于区分告警的严重程度
     */
    public enum AlertLevel {
        WARNING,     // 警告
        CRITICAL,    // 严重
        EMERGENCY    // 紧急
    }

    @PrePersist
    protected void onCreate() {
        alertTime = LocalDateTime.now();
    }
} 