package de.thpeetz.kontor.tysc.data;

import java.util.List;

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.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
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 = "firstName, lastName"),
        @Index(columnList = "lastName, firstName")
}, uniqueConstraints = {
        @UniqueConstraint(columnNames = { "firstName", "lastName" })
})
public class Player extends AbstractEntity {

    @NotNull
    private String firstName;

    @NotNull
    private String lastName;

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

    public String getFullName() {
        StringBuilder fullName = new StringBuilder();
        fullName.append(this.lastName);
        fullName.append(", ");
        fullName.append(this.firstName);
        return fullName.toString();
    }
}
