package com.gnx.telemedicine.repository;

import com.gnx.telemedicine.model.UserBlock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface UserBlockRepository extends JpaRepository<UserBlock, UUID> {
    
    @Query("SELECT ub FROM UserBlock ub WHERE ub.blocker.id = :blockerId AND ub.blocked.id = :blockedId")
    Optional<UserBlock> findByBlockerIdAndBlockedId(@Param("blockerId") UUID blockerId, @Param("blockedId") UUID blockedId);
    
    @Query("SELECT COUNT(ub) > 0 FROM UserBlock ub WHERE " +
           "(ub.blocker.id = :userId1 AND ub.blocked.id = :userId2) OR " +
           "(ub.blocker.id = :userId2 AND ub.blocked.id = :userId1)")
    boolean isBlocked(@Param("userId1") UUID userId1, @Param("userId2") UUID userId2);
    
    @Query("SELECT COUNT(ub) > 0 FROM UserBlock ub WHERE ub.blocker.id = :blockerId AND ub.blocked.id = :blockedId")
    boolean isBlockedBy(@Param("blockerId") UUID blockerId, @Param("blockedId") UUID blockedId);
    
    @Query("SELECT ub.blocked.id FROM UserBlock ub WHERE ub.blocker.id = :blockerId")
    List<UUID> findBlockedUserIdsByBlockerId(@Param("blockerId") UUID blockerId);
}

