package de.oaa.xxx.social.entity;

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

import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "notification_preference", uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "cause"}))
public class NotificationPreferenceEntity {

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

    @Column(name = "user_id", nullable = false)
    private UUID userId;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false, length = 20)
    private MessageCause cause;

    @Column(nullable = false)
    private boolean inApp = true;

    @Column(nullable = false)
    private boolean email = false;

    /** Erzeugt eine nicht persistierte Standardpräferenz für unbekannte/neue Causes. */
    public static NotificationPreferenceEntity defaultFor(UUID userId, MessageCause cause) {
        NotificationPreferenceEntity p = new NotificationPreferenceEntity();
        p.setUserId(userId);
        p.setCause(cause);
        // inApp=true und email=false sind bereits die Java-Felddefaults
        return p;
    }
}
