package de.thpeetz.kontor.tysc.data;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

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;
import lombok.ToString;

@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(indexes = {@Index(columnList = "cardNumber, year")},
        uniqueConstraints = {@UniqueConstraint(columnNames = { "cardNumber", "year", "vendor_id", "cardSet_id" })}
)
public class Card extends AbstractEntity {

    private int cardNumber;

    private int year;

    @ManyToOne
    @JoinColumn(name = "vendor_id")
    @NotNull
    @JsonIgnoreProperties({ "cards" })
    private Vendor vendor;

    @ManyToOne
    @JoinColumn(name = "cardSet_id")
    @NotNull
    @JsonIgnoreProperties({ "cards" })
    private CardSet cardSet;

    @ManyToOne
    @JoinColumn(name = "rooster_id")
    @NotNull
    @JsonIgnoreProperties({ "cards" })
    private Rooster rooster;

    public String getVendorName() {
        return this.vendor.getName();
    }

    public String getCardSetName() {
        return this.cardSet.getName();
    }

    public String getPlayerName() {
        return this.rooster.getPlayer().getFullName();
    }
}

