package de.thpeetz.kontor.comics.data;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.annotation.Nullable;
import de.thpeetz.kontor.common.data.AbstractEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.*;

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = false)
@Entity
public class StoryArc extends AbstractEntity {

    @NotEmpty
    private String name;

    @ManyToOne
    @JoinColumn(name = "comic_id")
    @NotNull
    @JsonIgnoreProperties({ "storyArcs" })
    private Comic comic;

    @ManyToOne
    @JoinColumn(name = "volume_id")
    @JsonIgnoreProperties({ "storyArcs" })
    @Nullable
    private Volume volume;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "storyArc", cascade = CascadeType.REMOVE, orphanRemoval = true)
    @Nullable
    private List<Issue> issues = new LinkedList<>();
}
