class PartyService {

    public InviteResult invite(String owner, String player) {
        if (playerMessaging.isOnline(player)) {
            return preferencesRepository.findBy(
                    new PlayerNameSpecification(player))
                    .filter(PlayerPreferences::isPartyRequests)
                    .map(playerProfile -> {
                        InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME);
                        if (result == InviteResult.INVITED) {
                            playerMessaging.sendTo(new PartyInvite(owner, player), player);
                        }
                        return result;
                    }).orElse(InviteResult.DISABLED);
        } else {
            return InviteResult.NOT_ONLINE;
        }


    }

}