class PunishmentChecker {

    public Optional<ActivePunishmentRecord> checkPunishment(UUID uuid, ActivePunishmentType activePunishmentType) {
        return punishmentDataRepository.getPunishmentData(uuid)
                .flatMap(punishmentData -> {
                    Optional<ActivePunishmentRecord> record = punishmentData.getPunishment(activePunishmentType);
                    return record.flatMap(activePunishmentRecord -> {
                        if (activePunishmentRecord.isExpired()) {
                            punishmentData.removePunishment(activePunishmentType);
                            taskFactory
                                    .newAsyncTask(() -> punishmentDataRepository.update(punishmentData))
                                    .execute();
                            return Optional.empty();
                        } else {
                            return record;
                        }
                    });
                });
    }

}