package info.bukova.isspst.ui.users;

import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;

public class RoleCheck {
	
	private Role role;
	private User user;
	private boolean checked;

	public RoleCheck(User user, Role role) {
		this.user = user;
		this.role = role;
		if (user.getAuthorities().contains(role)) {
			checked = true;
		} else {
			checked = false;
		}
	}
	
	public Role getRole() {
		return role;
	}
	
	public void setRole(Role role) {
		this.role = role;
	}
	
	public boolean isChecked() {
		return checked;
	}
	
	public void setChecked(boolean checked) {
		this.checked = checked;
		if (checked && !user.getAuthorities().contains(role)) {
			user.addAuthority(role);
		} else {
			user.removeAuthority(role);
		}
	}

}
