package com.example.cezenPBX.entity.user;

import jakarta.persistence.*;

import java.util.Collection;

@Entity
@Table(name = "roles")
final public class Role {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "role_id")
    private int id;

    //remember ROLE_
    @Column(name = "role_name")
    private String role;

    //all employees under this role
    // map by may be required
    @ManyToMany(
            fetch = FetchType.LAZY,
            cascade = {
                    //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context.
                    CascadeType.DETACH,
                    CascadeType.MERGE,
                    CascadeType.PERSIST,
                    CascadeType.REFRESH,
            }
            //cascade = CascadeType.ALL
    )
    @JoinTable(
            name = "user_roles",
            joinColumns = @JoinColumn(name = "role_id"),
            inverseJoinColumns = @JoinColumn(name = "u_id")
    )
    private Collection<UserEntity> employees;

    public Role(){}

    public Role(String role) {
        this.role = role;
    }

    public int getId() {
        return id;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Collection<UserEntity> getEmployees() {
        return employees;
    }

    public void setEmployees(Collection<UserEntity> employees) {
        this.employees = employees;
    }
}
