package cz.muni.fi.pa165.soccermanager.entity;

import cz.muni.fi.pa165.soccermanager.enums.Nation;
import cz.muni.fi.pa165.soccermanager.enums.PlayerState;
import cz.muni.fi.pa165.soccermanager.enums.Position;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.Objects;

/**
 * Player entity class
 *
 * @author Petr Adamec (uco 485548)
 */
@Getter
@Setter
@AllArgsConstructor
@RequiredArgsConstructor
@Entity
public class Player {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String name;

    @Enumerated(EnumType.STRING)
    private Nation nation;
    private int dressNumber;

    @NotNull
    private double height;

    @NotNull
    private double weight;

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

    @NotNull
    private LocalDate birthDate;

    @Enumerated(EnumType.STRING)
    private Position position;

    @Enumerated(EnumType.STRING)
    @NotNull
    private PlayerState state;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Player)) return false;

        Player player = (Player) o;

        if (getDressNumber() != player.getDressNumber()) return false;
        if (Double.compare(player.getHeight(), getHeight()) != 0) return false;
        if (Double.compare(player.getWeight(), getWeight()) != 0) return false;
        if (!getName().equals(player.getName())) return false;
        if (!getState().equals(player.getState())) return false;
        if (getNation() != null ? !getNation().equals(player.getNation()) : player.getNation() != null) return false;
        if (getTeam() != null ? !getTeam().equals(player.getTeam()) : player.getTeam() != null) return false;
        return getPosition() == player.getPosition();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }
}
