package cloud.nstart.terravault.ordinis.domain.idempotency;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.time.OffsetDateTime;

public interface IdempotencyKeyRepository extends JpaRepository<IdempotencyKey, String> {

  @Modifying
  @Transactional
  @Query("DELETE FROM IdempotencyKey k WHERE k.expiresAt < :now")
  int deleteExpired(@Param("now") OffsetDateTime now);
}
