package de.oaa.xxx.games.chastity.timelock;

import java.util.List;
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;

public interface TimeLockRepository extends JpaRepository<TimeLockEntity, UUID> {

    boolean existsByLockeeAndStartTimeIsNotNullAndUnlockTimeIsNull(UUID lockee);

    java.util.Optional<TimeLockEntity> findFirstByLockeeAndStartTimeIsNotNullAndUnlockTimeIsNull(UUID lockee);

    List<TimeLockEntity> findByKeyholderAndStartTimeIsNotNullAndUnlockTimeIsNull(UUID keyholder);

    @Modifying(clearAutomatically = true)
    @Query("DELETE FROM TimeLockEntity t WHERE t.lockId = :lockId")
    void deleteByLockId(UUID lockId);
}
