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

import java.util.List;

import lombok.*;

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

/**
 * League entity class
 *
 * @author Petr Balazy (uco: 527362)
 */
@Getter
@Setter
@AllArgsConstructor
@RequiredArgsConstructor
@Entity
public class League {

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

    @NotNull
    private String name;

    @NotNull
    private LocalDate startDate;

    @NotNull
    private LocalDate endDate;

    @OneToMany(mappedBy = "league", fetch = FetchType.LAZY)
    private List<Match> matches;

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

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

        League league = (League) o;

        if (!getName().equals(league.getName())) return false;
        if (!getStartDate().equals(league.getStartDate())) return false;
        if (!getEndDate().equals(league.getEndDate())) return false;
        if (getMatches() != null ? !getMatches().equals(league.getMatches()) : league.getMatches() != null)
            return false;
        return (getTeams() != null ? !getTeams().equals(league.getTeams()) : league.getTeams() != null) ;
    }

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