package de.oaa.xxx.social.repository;

import de.oaa.xxx.social.entity.ProfileVisitEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface ProfileVisitRepository extends JpaRepository<ProfileVisitEntity, UUID> {

    Optional<ProfileVisitEntity> findByProfileIdAndVisitorIdAndVisitedAtAfter(
            UUID profileId, UUID visitorId, LocalDateTime after);

    @Query("SELECT v FROM ProfileVisitEntity v WHERE v.profileId = :profileId ORDER BY v.visitedAt DESC")
    List<ProfileVisitEntity> findRecentByProfileId(@Param("profileId") UUID profileId, Pageable pageable);

    void deleteByProfileId(UUID profileId);

    void deleteByVisitorId(UUID visitorId);
}
