package dev.dinauer.maven.jpa.events;

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

import java.time.ZonedDateTime;

@Entity
@Table(name = "event")
public class Event
{
    @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 = "accountId")
    private String accountId;

    @Transient
    private User user;

    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 getAccountId()
    {
        return accountId;
    }

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

    public User getAccount()
    {
        return user;
    }

    public Event setAccount(User user)
    {
        this.user = user;
        return this;
    }
}
