package com.android.trisolarisserver.repo import com.android.trisolarisserver.models.room.IssuedCard import org.springframework.data.jpa.repository.JpaRepository import java.util.UUID interface IssuedCardRepo : JpaRepository { fun findByRoomStayIdOrderByIssuedAtDesc(roomStayId: UUID): List fun findByIdAndPropertyId(id: UUID, propertyId: UUID): IssuedCard? @org.springframework.data.jpa.repository.Query(""" select case when count(c) > 0 then true else false end from IssuedCard c where c.property.id = :propertyId and c.room.id = :roomId and c.revokedAt is null and c.expiresAt > :now """) fun existsActiveForRoom( @org.springframework.data.repository.query.Param("propertyId") propertyId: UUID, @org.springframework.data.repository.query.Param("roomId") roomId: UUID, @org.springframework.data.repository.query.Param("now") now: java.time.OffsetDateTime ): Boolean @org.springframework.data.jpa.repository.Query(""" select case when count(c) > 0 then true else false end from IssuedCard c where c.roomStay.id = :roomStayId and c.revokedAt is null and c.expiresAt > :now """) fun existsActiveForRoomStay( @org.springframework.data.repository.query.Param("roomStayId") roomStayId: UUID, @org.springframework.data.repository.query.Param("now") now: java.time.OffsetDateTime ): Boolean }