package org.academiadecodigo.enuminatti.hibernatebootstrap.associations.many2many;

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

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

@Entity
@Table(name = "user_many2many")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    @ManyToMany(fetch = FetchType.EAGER)
    private List<SecurityGroup> sgroups;

    public User(){
        sgroups = new LinkedList<>();
    }

    public User(String name) {
        this.name = name;
        this.sgroups = new LinkedList<>();
    }

    public Integer getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<SecurityGroup> getSgroups() {
        return sgroups;
    }

    public void setSgroups(List<SecurityGroup> sgroups) {
        this.sgroups = sgroups;
    }

    public void addSgroup(SecurityGroup sgroup) {
        sgroups.add(sgroup);
    }



    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sgroups=" + sgroups +
                '}';
    }
}
