package com.social.media.infrastructure.persistence.entity;

import jakarta.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * JPA Entity for NotificationSettings aggregate
 */
@Entity
@Table(name = "notification_settings",
       uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "notification_type", "event_type"}))
@EntityListeners(AuditingEntityListener.class)
public class NotificationSettingsEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;
    
    @Column(name = "user_id", nullable = false)
    private Long userId;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "notification_type", nullable = false)
    private NotificationTypeEntity notificationType;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "event_type", nullable = false)
    private EventTypeEntity eventType;
    
    @Column(name = "is_enabled", nullable = false)
    private boolean isEnabled = true;
    
    @CreatedDate
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    @LastModifiedDate
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;
    
    // Constructors
    public NotificationSettingsEntity() {}
    
    public NotificationSettingsEntity(Long id, Long userId, NotificationTypeEntity notificationType,
                                     EventTypeEntity eventType, boolean isEnabled) {
        this.id = id;
        this.userId = userId;
        this.notificationType = notificationType;
        this.eventType = eventType;
        this.isEnabled = isEnabled;
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public NotificationTypeEntity getNotificationType() {
        return notificationType;
    }
    
    public void setNotificationType(NotificationTypeEntity notificationType) {
        this.notificationType = notificationType;
    }
    
    public EventTypeEntity getEventType() {
        return eventType;
    }
    
    public void setEventType(EventTypeEntity eventType) {
        this.eventType = eventType;
    }
    
    public boolean isEnabled() {
        return isEnabled;
    }
    
    public void setEnabled(boolean enabled) {
        isEnabled = enabled;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
}
