package de.oaa.xxx.social.repository;

import de.oaa.xxx.social.entity.ProfileImageLikeEntity;
import jakarta.transaction.Transactional;
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 java.util.Optional;
import java.util.UUID;

public interface ProfileImageLikeRepository extends JpaRepository<ProfileImageLikeEntity, UUID> {

    Optional<ProfileImageLikeEntity> findByImageIdAndUserId(UUID imageId, UUID userId);

    long countByImageId(UUID imageId);

    @Modifying
    @Transactional
    @Query("DELETE FROM ProfileImageLikeEntity l WHERE l.imageId = :imageId")
    void deleteByImageId(@Param("imageId") UUID imageId);

    @Modifying
    @Transactional
    @Query("DELETE FROM ProfileImageLikeEntity l WHERE l.userId = :userId")
    void deleteByUserId(@Param("userId") UUID userId);
}
