package de.thpeetz.kontor.tysc.data;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

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.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(indexes = {@Index(columnList = "name, sport_id")},
        uniqueConstraints = {
            @UniqueConstraint(columnNames = { "name", "sport_id" }),
            @UniqueConstraint(columnNames = { "shortName", "sport_id" })
        }
)
public class FieldPosition extends AbstractEntity {

    @NotEmpty
    private String name;

    @NotEmpty
    private String shortName;

    @ManyToOne
    @JoinColumn(name = "sport_id")
    @NotNull
    @JsonIgnoreProperties({ "positions" })
    private Sport sport;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "position")
    @Nullable
    private List<Rooster> roosters;
}