package de.thpeetz.kontor.comics.data;

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

import de.thpeetz.kontor.common.data.AbstractEntity;
import io.micrometer.common.lang.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotEmpty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Represents a work type in the application.
 * This class extends the AbstractEntity class.
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Entity
public class Worktype extends AbstractEntity {

    @NotEmpty
    @Column(unique = true)
    private String name;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "workType", cascade = CascadeType.REFRESH, orphanRemoval = true)
    @Nullable
    List<ComicWork> comicWorks = new LinkedList<>();

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "workType", cascade = CascadeType.REFRESH, orphanRemoval = true)
    @Nullable
    List<IssueWork> issueWorks = new LinkedList<>();

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Worktype{");
        sb.append("name='").append(name).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
