package dev.dinauer.maven.event;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import dev.dinauer.maven.shared.UserReferencing;
import dev.dinauer.maven.user.User;
import jakarta.persistence.*;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "event")
public class Event implements UserReferencing
{
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private String id;

    @Enumerated(EnumType.STRING)
    private EventType type;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "resource_id")
    @JsonManagedReference
    private Resource resource;

    private ZonedDateTime timestamp;

    @Column(name = "user_id")
    private String userId;

    public String getId()
    {
        return id;
    }

    public Event setId(String id)
    {
        this.id = id;
        return this;
    }

    public Resource getResource()
    {
        return resource;
    }

    public Event setResource(Resource resource)
    {
        this.resource = resource;
        return this;
    }

    public ZonedDateTime getTimestamp()
    {
        return timestamp;
    }

    public Event setTimestamp(ZonedDateTime timestamp)
    {
        this.timestamp = timestamp;
        return this;
    }

    public EventType getType()
    {
        return type;
    }

    public Event setType(EventType type)
    {
        this.type = type;
        return this;
    }

    public String getUserId()
    {
        return userId;
    }

    public Event setUserId(String userId)
    {
        this.userId = userId;
        return this;
    }

    @Override
    public Set<String> getUserIds()
    {
        return Set.of(userId);
    }
}
