class PossibleActionsRuleEngine {

    public EnumSet<PossibleActionEnum> getPossibleKeyActions(TokenInfo tokenInfo,
            KeyInfo keyInfo) {
        EnumSet<PossibleActionEnum> actions = EnumSet.noneOf(PossibleActionEnum.class);

        // DELETE
        boolean keyNotSupported = isKeyUnsupported(tokenInfo, keyInfo);

        // key.js#L26
        // original logic pieces preserved, could be simplified
        if (tokenInfo.isActive()
                && !keyNotSupported
                && !(tokenInfo.isReadOnly() && !keyInfo.isSavedToConfiguration())
                && (keyInfo.isSavedToConfiguration() || tokenInfo.isActive())) {
            actions.add(PossibleActionEnum.DELETE);
        }

        // GENERATE_AUTH_CSR
        // keys.js#35
        if (SOFTWARE_TOKEN_ID.equals(tokenInfo.getId())
                && (keyInfo.getUsage() == null || keyInfo.getUsage() == KeyUsageInfo.AUTHENTICATION)
                && !(!keyInfo.isAvailable() || !tokenInfo.isActive() || keyNotSupported)) {
            actions.add(PossibleActionEnum.GENERATE_AUTH_CSR);
        }
        // GENERATE_SIGN_CSR
        if ((keyInfo.getUsage() == null || keyInfo.getUsage() == KeyUsageInfo.SIGNING)
                && !(!keyInfo.isAvailable() || !tokenInfo.isActive() || keyNotSupported)) {
            actions.add(PossibleActionEnum.GENERATE_SIGN_CSR);
        }
        // EDIT_FRIENDLY_NAME
        actions.add(PossibleActionEnum.EDIT_FRIENDLY_NAME);

        return actions;
    }

}