package at.ac.tuwien.inso.entity;

import javax.persistence.*;

@Entity
public class SubjectForStudyPlan {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(optional = false)
    private Subject subject;

    @Column(nullable = false)
    private Boolean mandatory;

    private Integer semesterRecommendation;

    protected SubjectForStudyPlan() {
    }

    public SubjectForStudyPlan(Subject subject, Boolean mandatory) {
        this(subject, mandatory, null);
    }

    public SubjectForStudyPlan(Subject subject, Boolean mandatory, Integer semesterRecommendation) {

        this.subject = subject;
        this.mandatory = mandatory;
        this.semesterRecommendation = semesterRecommendation;
    }

    public Long getId() {
        return id;
    }

    public Subject getSubject() {
        return subject;
    }

    public Boolean getMandatory() {
        return mandatory;
    }

    public Integer getSemesterRecommendation() {
        return semesterRecommendation;
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SubjectForStudyPlan that = (SubjectForStudyPlan) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false;
        if (mandatory != null ? !mandatory.equals(that.mandatory) : that.mandatory != null) return false;
        return semesterRecommendation != null ? semesterRecommendation.equals(that.semesterRecommendation) : that.semesterRecommendation == null;

    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (subject != null ? subject.hashCode() : 0);
        result = 31 * result + (mandatory != null ? mandatory.hashCode() : 0);
        result = 31 * result + (semesterRecommendation != null ? semesterRecommendation.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "SubjectForStudyPlan{" +
                "id=" + id +
                ", subject=" + subject +
                ", mandatory=" + mandatory +
                ", semesterRecommendation=" + semesterRecommendation +
                '}';
    }
}

@@ -214,16 +214,83 @@
 bject;%0A%0A
+    @ManyToOne(optional = false)%0A    private StudyPlan studyPlan;%0A%0A
     @Col
@@ -472,32 +472,53 @@
 Subject subject,
+ StudyPlan studyPlan,
  Boolean mandato
@@ -544,16 +544,27 @@
 subject,
+ studyPlan,
  mandato
@@ -628,16 +628,37 @@
 subject,
+ StudyPlan studyPlan,
  Boolean
@@ -732,24 +732,60 @@
  = subject;%0A
+        this.studyPlan = studyPlan;%0A
         this
@@ -1150,32 +1150,103 @@
 ndation;%0A    %7D%0A%0A
+    public StudyPlan getStudyPlan() %7B%0A        return studyPlan;%0A    %7D%0A%0A
     @Override%0A  

add missing attribute for study plan.