package de.fete.adapter.out.persistence;

import java.util.Optional;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/** Spring Data JPA repository for event entities. */
public interface EventJpaRepository extends JpaRepository<EventJpaEntity, Long> {

  /** Finds an event by its public event token. */
  Optional<EventJpaEntity> findByEventToken(UUID eventToken);

  /** Deletes all events whose expiry date is before today. Returns the number of deleted rows. */
  @Modifying
  @Query(value = "DELETE FROM events WHERE expiry_date < CURRENT_DATE", nativeQuery = true)
  int deleteExpired();
}
