class TokenConverter {

    public Token convert(TokenInfo tokenInfo) {
        Token token = new Token();
        token.setId(tokenInfo.getId());
        token.setName(tokenInfo.getFriendlyName());

        // software module has a magic type string, hardware modules have device UI as type
        if (TokenInfo.SOFTWARE_MODULE_TYPE.equals(tokenInfo.getType())) {
            token.setType(TokenType.SOFTWARE);
        } else {
            token.setType(TokenType.HARDWARE);
        }

        token.setKeys(keyConverter.convert(tokenInfo.getKeyInfo()));

        Optional<TokenStatus> status = TokenStatusMapping.map(tokenInfo.getStatus());
        token.setStatus(status.orElse(null));

        token.setLoggedIn(tokenInfo.isActive());
        token.setAvailable(tokenInfo.isAvailable());
        token.setSavedToConfiguration(isSavedToConfiguration(tokenInfo));
        token.setReadOnly(tokenInfo.isReadOnly());
        token.setSerialNumber(tokenInfo.getSerialNumber());
        token.setTokenInfos(new ArrayList<>());

        for (String key: tokenInfo.getTokenInfo().keySet()) {
            KeyValuePair keyValuePair = new KeyValuePair();
            keyValuePair.setKey(key);
            keyValuePair.setValue(tokenInfo.getTokenInfo().get(key));
            token.getTokenInfos().add(keyValuePair);
        }

        return token;
    }

    @Autowired public  TokenConverter(KeyConverter keyConverter);

}