package dev.lions.unionflow.server.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

/**
 * Entité singleton pour la configuration des alertes système.
 * Une seule ligne en base de données.
 *
 * @author UnionFlow Team
 * @version 1.0
 * @since 2026-03-15
 */
@Entity
@Table(name = "alert_configuration")
@Getter
@Setter
public class AlertConfiguration extends BaseEntity {

    /**
     * Alerte CPU activée
     */
    @Column(name = "cpu_high_alert_enabled", nullable = false)
    private Boolean cpuHighAlertEnabled = true;

    /**
     * Seuil CPU en pourcentage (0-100)
     */
    @Column(name = "cpu_threshold_percent", nullable = false)
    private Integer cpuThresholdPercent = 80;

    /**
     * Durée en minutes avant déclenchement alerte CPU
     */
    @Column(name = "cpu_duration_minutes", nullable = false)
    private Integer cpuDurationMinutes = 5;

    /**
     * Alerte mémoire faible activée
     */
    @Column(name = "memory_low_alert_enabled", nullable = false)
    private Boolean memoryLowAlertEnabled = true;

    /**
     * Seuil mémoire en pourcentage (0-100)
     */
    @Column(name = "memory_threshold_percent", nullable = false)
    private Integer memoryThresholdPercent = 85;

    /**
     * Alerte erreur critique activée
     */
    @Column(name = "critical_error_alert_enabled", nullable = false)
    private Boolean criticalErrorAlertEnabled = true;

    /**
     * Alerte erreur activée
     */
    @Column(name = "error_alert_enabled", nullable = false)
    private Boolean errorAlertEnabled = true;

    /**
     * Alerte échec de connexion activée
     */
    @Column(name = "connection_failure_alert_enabled", nullable = false)
    private Boolean connectionFailureAlertEnabled = true;

    /**
     * Seuil d'échecs de connexion
     */
    @Column(name = "connection_failure_threshold", nullable = false)
    private Integer connectionFailureThreshold = 100;

    /**
     * Fenêtre temporelle en minutes pour les échecs de connexion
     */
    @Column(name = "connection_failure_window_minutes", nullable = false)
    private Integer connectionFailureWindowMinutes = 5;

    /**
     * Notifications par email activées
     */
    @Column(name = "email_notifications_enabled", nullable = false)
    private Boolean emailNotificationsEnabled = true;

    /**
     * Notifications push activées
     */
    @Column(name = "push_notifications_enabled", nullable = false)
    private Boolean pushNotificationsEnabled = false;

    /**
     * Notifications SMS activées
     */
    @Column(name = "sms_notifications_enabled", nullable = false)
    private Boolean smsNotificationsEnabled = false;

    /**
     * Liste des emails destinataires des alertes (séparés par virgule)
     */
    @Column(name = "alert_email_recipients", length = 1000)
    private String alertEmailRecipients = "admin@unionflow.test";

    /**
     * S'assurer qu'il n'y a qu'une seule configuration
     */
    @PrePersist
    @PreUpdate
    protected void ensureSingleton() {
        // La logique singleton sera gérée par le repository
    }
}
