package com.qqchen.deploy.backend.deploy.entity;

import com.qqchen.deploy.backend.framework.enums.MonitorAlertLevelEnum;
import com.qqchen.deploy.backend.framework.enums.MonitorMetricEnum;
import com.qqchen.deploy.backend.framework.enums.ServerAlertStatusEnum;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 服务器告警记录实体
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "deploy_server_alert_log")
public class ServerAlertLog {

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

    /**
     * 服务器ID
     */
    @Column(name = "server_id", nullable = false)
    private Long serverId;

    /**
     * 规则ID
     */
    @Column(name = "rule_id")
    private Long ruleId;

    /**
     * 监控指标类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "alert_type", nullable = false, length = 20)
    private MonitorMetricEnum alertType;

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

    /**
     * 当前值
     */
    @Column(name = "alert_value", nullable = false, precision = 5, scale = 2)
    private BigDecimal alertValue;

    /**
     * 阈值
     */
    @Column(name = "threshold_value", nullable = false, precision = 5, scale = 2)
    private BigDecimal thresholdValue;

    /**
     * 告警消息
     */
    @Column(name = "alert_message", length = 500)
    private String alertMessage;

    /**
     * 状态: PENDING/ACTIVE/RESOLVED
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 20)
    private ServerAlertStatusEnum status;

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

    /**
     * 恢复时间
     */
    @Column(name = "resolve_time")
    private LocalDateTime resolveTime;

    /**
     * 是否已通知
     */
    @Column(name = "notified")
    private Boolean notified = false;

    /**
     * 通知时间
     */
    @Column(name = "notify_time")
    private LocalDateTime notifyTime;
}
