package de.thpeetz.kontor.bookshelf.data;

import java.util.LinkedList;
import java.util.List;

import de.thpeetz.kontor.common.data.AbstractEntity;
import jakarta.annotation.Nullable;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Index;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@Table(indexes = @Index(columnList = "name"), uniqueConstraints = @UniqueConstraint(columnNames = { "name" }))
public class BookshelfPublisher extends AbstractEntity {

    @NotEmpty
    private String name;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "publisher", orphanRemoval = true)
    @Nullable
    List<Book> books = new LinkedList<>();
}
