package de.thpeetz.kontor.comics.data;

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

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import de.thpeetz.kontor.common.data.AbstractEntity;
import jakarta.annotation.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Entity
public class Volume extends AbstractEntity {
    
    @NotEmpty
    private String name;

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

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "volume", cascade = CascadeType.REMOVE, orphanRemoval = true)
    @Nullable
    private List<StoryArc> storyArcs =  new LinkedList<>();

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

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("Volume{");
        result.append("name=");
        result.append(name);
        result.append("comic=Comic{title=");
        result.append(comic.getTitle());
        result.append("}}");
        return result.toString();
    }
}
