package models;

import modules.preloader.DatabasePreloader;

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

import static models.PropertyTypeData.PHONE_NUMBER;
import static models.PropertyTypeData.WORK_PHONE_NUMBER;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.apache.commons.lang3.text.WordUtils.capitalizeFully;

@Entity
@Table(name = "people")
public class Person {
    @Id
    @GeneratedValue
    @Column(name = "person_id")
    private int id;

    @Column(name = "first_name", nullable = false)
    private String firstName;

    @Column(name = "middle_name")
    private String middleName;

    @Column(name = "last_name", nullable = false)
    private String lastName;

    @Column(name = "display_name", nullable = false)
    private String displayName;

    @OneToOne(fetch = FetchType.LAZY)
    private File photo;

    @OneToMany(mappedBy = "person", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<PersonInfo> info = new ArrayList<>();

    @ManyToMany(mappedBy = "members", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Group> memberOf = new ArrayList<>();

    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Group selfGroup;

    @OneToMany(mappedBy = "author", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Message> messages = new ArrayList<>();

    @ManyToMany(mappedBy = "tags", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Message> taggedIn = new ArrayList<>();

    @ManyToMany(mappedBy = "upvotes", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Message> upvotesIn = new ArrayList<>();

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public List<PersonInfo> getInfo() {
        return info;
    }

    public List<Group> getMemeberOf() {
        return memberOf;
    }

    public File getPhoto() {
        return photo;
    }

    public void setPhoto(File photo) {
        this.photo = photo;
    }

    public Group getSelfGroup() {
        return selfGroup;
    }

    public void setSelfGroup(Group selfGroup) {
        this.selfGroup = selfGroup;
    }

    public List<Message> getMessages() {
        return messages;
    }
    
    public List<Message> getTaggedIn() {
        return taggedIn;
    }

    static {
        DatabasePreloader.addTest((em -> {
            for (int i = 0; i < 100; i++) {
                Person person = new Person();
                person.setFirstName(capitalizeFully(randomAlphabetic(10)));
                person.setLastName(capitalizeFully(randomAlphabetic(15)));
                person.setDisplayName(person.getFirstName() + " " + person.getLastName());
                em.persist(person);

                em.persist(new PersonInfo(person, PHONE_NUMBER, randomNumeric(9)));
                em.persist(new PersonInfo(person, WORK_PHONE_NUMBER, randomNumeric(9)));
            }
        }), 10);
    }
}

@@ -1809,24 +1809,471 @@
 yList%3C%3E();%0A%0A
+    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)%0A    @JoinTable(%0A            name = %22friends%22,%0A            joinColumns = %7B@JoinColumn(name = %22person_id%22)%7D,%0A            inverseJoinColumns = %7B@JoinColumn(name = %22friend_id%22)%7D%0A    )%0A    private List%3CPerson%3E friends = new ArrayList%3C%3E();%0A%0A    @ManyToMany(mappedBy = %22friends%22, fetch = FetchType.LAZY, cascade = CascadeType.ALL)%0A    private List%3CPerson%3E friendOf = new ArrayList%3C%3E();%0A%0A
     public i

Add ManyToMany Relation in Person model