package de.thpeetz.kontor.tysc.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 = "team_id, player_id, position_id") }, uniqueConstraints = {
        @UniqueConstraint(name = "uniqueRooster", columnNames = { "year", "team_id", "player_id", "position_id" }) })
public class Rooster extends AbstractEntity {

    private int year;

    @ManyToOne
    @JoinColumn(name = "team_id")
    @NotNull
    private Team team;

    @ManyToOne
    @JoinColumn(name = "player_id")
    @NotNull
    private Player player;

    @ManyToOne
    @JoinColumn(name = "position_id")
    @NotNull
    private FieldPosition position;

    @Override
    public String toString() {
        return "Rooster{" +
                "year=" + year +
                ", team=" + team.getName() +
                ", player=" + player.getFullName() +
                ", position=" + position.getName() +
                '}';
    }
}
