package info.bukova.isspst.ui.users;

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

public class PermissionCheck {
	
	private Role role;
	private Permission permission;
	private boolean checked;

	public PermissionCheck(Role role, Permission permission) {
		this.role = role;
		this.permission = permission;
		
		if (role.getPermissions().contains(permission)) {
			checked = true;
		} else {
			checked = false;
		}
	}
	
	public Permission getPermission() {
		return permission;
	}

	public void setPermission(Permission permission) {
		this.permission = permission;
	}

	public boolean isChecked() {
		return checked;
	}
	
	public void setChecked(boolean checked) {
		this.checked = checked;
		if (checked && !role.getPermissions().contains(permission)) {
			role.addPermission(permission);
		} else {
			role.getPermissions().remove(permission);
		}
	}

}
