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

import cz.muni.fi.pa165.soccermanager.enums.Nation;
import java.util.List;

import lombok.*;

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

/**
 * Championship entity class
 *
 * @author Stanislav Koshchienko (uco: 506549)
 */
@Getter
@Setter
@AllArgsConstructor
@RequiredArgsConstructor
@NoArgsConstructor
@Entity
public class Championship {

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

    @NotNull
    private String name;

    @NonNull
    @Enumerated(EnumType.STRING)
    private Nation country;

    @OneToMany(mappedBy = "championship", fetch = FetchType.LAZY)
    private List<Team> teams;

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

        Championship that = (Championship) o;

        if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
        if (getCountry() != null ? !getCountry().equals(that.getCountry()) : that.getCountry() != null) return false;
        return getTeams() != null ? getTeams().equals(that.getTeams()) : that.getTeams() == null;
    }

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