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

import lombok.*;

import javax.persistence.*;
import java.util.Objects;

/**
 * User entity class
 *
 * @author Vitalii Bortsov (uco: 514699)
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "Users")
public class User {

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

    @Column(nullable = false, length = 64)
    private String password;

    @Column(name = "nickName", unique = true, nullable = false, length = 50)
    private String nickName;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "user")
    private Team team;

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

        User user = (User) o;

        if (!getPassword().equals(user.getPassword())) {
            return false;
        }
        if (!getNickName().equals(user.getNickName())) {
            return false;
        }

        return (getTeam() != null ? !getTeam().equals(user.getTeam()) : user.getTeam() != null);
    }

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

}