package cz.utb.tadis.news.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import cz.utb.tadis.auth.model.UserName;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.Set;


@Entity
@Table(name = "news")
public class New {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    @Size(max = 500)
    private String title;

    @NotBlank
    @Size(max = 10000)
    private String text;

    @NotNull
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "new_id")
    private Set<Attachment> attachments;

    @NotNull
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "author_id")
    private UserName author;

    @NotNull
    private LocalDateTime created;

    public New() {
    }

    public New(@NotBlank @Size(max = 500) String title, @NotBlank @Size(max = 10000) String text, @NotNull Set<Attachment> attachments, @NotNull UserName author, @NotNull LocalDateTime created) {
        this.title = title;
        this.text = text;
        this.attachments = attachments;
        this.author = author;
        this.created = created;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Set<Attachment> getAttachments() {
        return attachments;
    }

    public void setAttachments(Set<Attachment> attachments) {
        this.attachments = attachments;
    }

    public UserName getAuthor() {
        return author;
    }

    public void setAuthor(UserName author) {
        this.author = author;
    }

    public LocalDateTime getCreated() {
        return created;
    }

    public void setCreated(LocalDateTime created) {
        this.created = created;
    }
}
