package de.cannamanage.domain.entity;

import de.cannamanage.domain.enums.RsvpStatus;
import jakarta.persistence.*;

import java.time.Instant;
import java.util.UUID;

/**
 * Event RSVP entity — tracks member attendance responses.
 * Unique constraint on (event_id, member_id) ensures one RSVP per member per event.
 */
@Entity
@Table(name = "event_rsvps",
    uniqueConstraints = @UniqueConstraint(
        name = "uq_event_rsvps_event_member",
        columnNames = {"event_id", "member_id"}
    ),
    indexes = {
        @Index(name = "idx_event_rsvps_event", columnList = "event_id"),
        @Index(name = "idx_event_rsvps_member", columnList = "member_id")
    }
)
public class EventRsvp extends AbstractTenantEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "event_id", nullable = false)
    private ClubEvent event;

    @Column(name = "member_id", nullable = false)
    private UUID memberId;

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private RsvpStatus status;

    @Column(name = "responded_at", nullable = false)
    private Instant respondedAt;

    public EventRsvp() {}

    public EventRsvp(ClubEvent event, UUID memberId, RsvpStatus status) {
        this.event = event;
        this.memberId = memberId;
        this.status = status;
        this.respondedAt = Instant.now();
    }

    // Getters and Setters

    public ClubEvent getEvent() { return event; }
    public void setEvent(ClubEvent event) { this.event = event; }

    public UUID getMemberId() { return memberId; }
    public void setMemberId(UUID memberId) { this.memberId = memberId; }

    public RsvpStatus getStatus() { return status; }
    public void setStatus(RsvpStatus status) { this.status = status; }

    public Instant getRespondedAt() { return respondedAt; }
    public void setRespondedAt(Instant respondedAt) { this.respondedAt = respondedAt; }
}
