package de.thpeetz.kontor.comics.data;

import de.thpeetz.kontor.common.data.AbstractEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(indexes = {@Index(columnList = "issue_id, artist_id, workType_id") },
        uniqueConstraints = @UniqueConstraint(columnNames = {"issue_id", "artist_id", "workType_id" })
)
public class IssueWork extends AbstractEntity {

    @ManyToOne
    @JoinColumn(name = "issue_id")
    @NotNull
    private Issue issue;

    @ManyToOne
    @JoinColumn(name = "artist_id")
    @NotNull
    private Artist artist;

    @ManyToOne
    @JoinColumn(name = "workType_id")
    @NotNull
    private Worktype workType;

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("IssueWork{");
        sb.append("issue=").append(issue);
        sb.append(", artist=").append(artist);
        sb.append(", workType=").append(workType);
        sb.append('}');
        return sb.toString();
    }
}
