package com.ssj.dao.sys.schoolmatecircle.dao;

import com.ssj.bean.sys.schoolmatecircle.domain.SSJUserFriendApply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SSJUserFriendApplyDao extends JpaRepository<SSJUserFriendApply, String> {

//	@Query(nativeQuery = true, value = "update ssj_user_friend_apply set status = ?3 where (owner_user_id = ?1 and friend_user_id = ?2) "
//			+ "or (owner_user_id = ?2 and friend_user_id = ?1)")
//	@Modifying
//	public void updateUserFriendApplyStatus(String userId,String friendUserId,int status);
	
	
	@Query(nativeQuery = true, value = "update ssj_user_friend_apply set status = ?3 where (friend_user_id = ?1 and owner_user_id = ?2)")
	@Modifying
	public void updateUserFriendApplyStatus(String userId,String friendUserId,int status);
	
	@Query(nativeQuery = true, value = "select count(*) from  ssj_user_friend_apply  where ((friend_user_id = ?1 and owner_user_id = ?2) "
			+ "or (owner_user_id = ?2 and friend_user_id = ?1)) and `status` = 2")
	public int countByRefuseUserFriendApply(String userId,String friendUserId);
	
	public SSJUserFriendApply findByOwnerUserIdAndFriendUserId(String userId,String friendUserId);
	
	@Query(nativeQuery = true, value = "delete from ssj_user_friend_apply where (owner_user_id = ?1 and friend_user_id = ?2) or (owner_user_id = ?2 and friend_user_id = ?1)")
	@Modifying
	public void deleteFriendApply(String userId,String friendUserId);

	@Query(nativeQuery = true, value = "delete from ssj_user_friend_apply where owner_user_id = ?1 or friend_user_id = ?1")
	@Modifying
	public void deleteFriendsApply(String userId);
	
	public List<SSJUserFriendApply> findByOwnerUserIdOrFriendUserId(String userId,String friendUserId);
}
