package se.kits.gakusei.content.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.List;
import java.util.UUID;

@Entity
@Table(name = "kanjis", schema = "contentschema")
public class Kanji {

    @Id
    private String id = UUID.randomUUID().toString();

    private String description;

    private boolean hidden = false;

    @ManyToOne
    @JsonBackReference(value = "kanji_book")
    @JoinColumn(name = "book_ref")
    private Book title;

    private String swedish;

    private String english;

    private String kanji;

    @ManyToMany(mappedBy = "kanjis")
    @JsonIgnore
    private List<Lesson> lessons;

    public String getId() {
        return id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean isHidden() {
        return hidden;
    }

    public void setHidden(boolean hidden) {
        this.hidden = hidden;
    }

    public Book getTitle() {
        return title;
    }

    public void setTitle(Book title) {
        this.title = title;
    }

    public String getSwedish() {
        return swedish;
    }

    public void setSwedish(String swedish) {
        this.swedish = swedish;
    }

    public String getEnglish() {
        return english;
    }

    public void setEnglish(String english) {
        this.english = english;
    }

    public String getKanji() {
        return kanji;
    }

    public void setKanji(String kanji) {
        this.kanji = kanji;
    }

    public List<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(List<Lesson> lessons) {
        this.lessons = lessons;
    }
}

@@ -448,114 +448,404 @@
 nyTo
-One
+Many
 %0A    @J
-sonBackReference(value = %22kanji_book
+oinTable(%0A            name = %22kanji_books%22,%0A            schema = %22contentschema%22,%0A            joinColumns = @JoinColumn(name = %22kanji_id%22, referencedColumnName = %22id
 %22)
+,
 %0A    
-@JoinColumn(name = %22book_ref
+        inverseJoinColumns = @JoinColumn(name = %22book_id%22, referencedColumnName = %22id
 %22)
+,
 %0A    
-private Book title
+        uniqueConstraints = @UniqueConstraint(columnNames = %7B%22kanji_id%22, %22book_id%22%7D)%0A    )%0A    private List%3CBook%3E books
 ;%0A%0A 
@@ -1400,21 +1400,27 @@
 lic 
+List%3C
 Book
+%3E
  get
-Title
+Books
 () %7B
@@ -1435,21 +1435,21 @@
  return 
-title
+books
 ;%0A    %7D%0A
@@ -1472,24 +1472,30 @@
  set
-Title(Book title
+Books(List%3CBook%3E books
 ) %7B%0A
@@ -1511,21 +1511,21 @@
 his.
-title = title
+books = books
 ;%0A  

Use list of books instead of only one book