class NonRecurringConsentExpirationScheduleTask {

    @Scheduled(cron = "${xs2a.cms.used-non-recurring-consent-expiration.cron.expression}")
    @Transactional
    public void expireUsedNonRecurringConsent() {
        log.info("Non-recurring consent expiration task has started!");
        List<ConsentEntity> consents = consentJpaRepository.findUsedNonRecurringConsents(EnumSet.of(RECEIVED, VALID),
                                                                                      LocalDate.now())
                                        .stream()
                                        .distinct()
                                        .map(this::expireConsent)
                                        .collect(Collectors.toList());

        consentJpaRepository.saveAll(consents);
    }

}