package at.ac.tuwien.inso.entity;

import javax.persistence.*;
import java.math.*;
import java.util.ArrayList;
import java.util.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;

@Entity
public class Subject {

    @Id
    @GeneratedValue
    private Long id;

    @Column(nullable = false)
    private String name;

    @Column(nullable = false)
    private BigDecimal ects;

    @ManyToMany
    private List<Lecturer> lecturers = new ArrayList<>();

    @ManyToMany
    private List<Subject> requiredSubjects = new ArrayList<>();

    protected Subject() {
    }

    public Subject(String name, BigDecimal ects) {
        this.name = name;
        this.ects = ects;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public BigDecimal getEcts() {
        return ects;
    }

    public List<Lecturer> getLecturers() {
        return unmodifiableList(lecturers);
    }

    public List<Subject> getRequiredSubjects() {
        return requiredSubjects;
    }

    public void addLecturers(Lecturer... lecturers) {
        this.lecturers.addAll(asList(lecturers));
    }

    public void removeLecturers(Lecturer... lecturers) {
        this.lecturers.removeAll(asList(lecturers));
    }

    public void addRequiredSubjects(Subject... subjects) {
        this.requiredSubjects.addAll(asList(subjects));
    }

    public void removeRequiredSubjects(Subject... subjects) {
        this.requiredSubjects.removeAll(asList(subjects));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Subject subject = (Subject) o;

        if (getId() != null ? !getId().equals(subject.getId()) : subject.getId() != null) return false;
        if (getName() != null ? !getName().equals(subject.getName()) : subject.getName() != null) return false;
        if (getEcts() != null ? !getEcts().equals(subject.getEcts()) : subject.getEcts() != null) return false;
        return getLecturers() != null ? getLecturers().equals(subject.getLecturers()) : subject.getLecturers() == null;

    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getName() != null ? getName().hashCode() : 0);
        result = 31 * result + (getEcts() != null ? getEcts().hashCode() : 0);
        result = 31 * result + (getLecturers() != null ? getLecturers().hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Subject{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", ects=" + ects +
                ", lecturers=" + lecturers +
                '}';
    }
}

@@ -1741,84 +1741,30 @@
 if (
-getId() != null ? !getId().equals(subject.getId()) : subject.getId() != null
+!id.equals(subject.id)
 ) re
@@ -1791,38 +1791,13 @@
 if (
-getName() != null ? !getN
+!n
 ame
-()
 .equ
@@ -1812,292 +1812,211 @@
 ect.
-getN
+n
 ame
-(
 )) 
-: subject.getName() != null) return false;%0A        if (getEcts() != null ? !getEcts().equals(subject.getEcts()) : subject.getEcts() != null) return false;%0A        return getLecturers() != null ? getLecturers().equals(subject.getLecturers()) : subject.getLecturers() == null
+return false;%0A        if (!ects.equals(subject.ects)) return false;%0A        if (!lecturers.equals(subject.lecturers)) return false;%0A        return requiredSubjects.equals(subject.requiredSubjects)
 ;%0A%0A 
@@ -2088,33 +2088,10 @@
 t = 
-getId() != null ? getId()
+id
 .has
@@ -2097,20 +2097,16 @@
 shCode()
- : 0
 ;%0A      
@@ -2134,38 +2134,12 @@
 t + 
-(getName() != null ? getN
+n
 ame
-()
 .has
@@ -2137,37 +2137,32 @@
  name.hashCode()
- : 0)
 ;%0A        result
@@ -2182,38 +2182,12 @@
 t + 
-(getEcts() != null ? getEcts()
+ects
 .has
@@ -2185,37 +2185,32 @@
  ects.hashCode()
- : 0)
 ;%0A        result
@@ -2230,21 +2230,17 @@
 t + 
-(getL
+l
 ecturers
 () !
@@ -2239,35 +2239,68 @@
 rers
-() != null ? getLecturers()
+.hashCode();%0A        result = 31 * result + requiredSubjects
 .has
@@ -2310,13 +2310,8 @@
 de()
- : 0)
 ;%0A  
@@ -2559,24 +2559,83 @@
 lecturers +%0A
+                %22, requiredSubjects=%22 + requiredSubjects +%0A
             

update equals, hashCode and toString.