package app.mealsmadeeasy.api.image;

import app.mealsmadeeasy.api.user.User;
import jakarta.persistence.*;
import lombok.Data;

import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "image")
@Data
public class Image {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, updatable = false)
    private Integer id;

    @Column(nullable = false)
    private OffsetDateTime created = OffsetDateTime.now();

    private OffsetDateTime modified;

    @Column(nullable = false)
    private String userFilename;

    @Column(nullable = false)
    private String mimeType;

    private String alt;

    private String caption;

    @Column(nullable = false)
    private String objectName;

    private Integer height;

    private Integer width;

    @ManyToOne(optional = false)
    @JoinColumn(name = "owner_id", nullable = false)
    private User owner;

    @Column(nullable = false)
    private Boolean isPublic = false;

    @ManyToMany
    @JoinTable(
            name = "image_viewer",
            joinColumns = @JoinColumn(name = "image_id"),
            inverseJoinColumns = @JoinColumn(name = "viewer_id")
    )
    private Set<User> viewers = new HashSet<>();

}
