package com.example.system.chat.mapper;

import com.example.system.chat.model.Friend;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FriendMapper {
    /**
     * 根据用户id获取好友列表
     */
    @Select("select friend_id, friend_name from friend where user_id=#{userId};")
    List<Friend> getFriendList(Integer userId);

    /**
     * 判断用户之间的关系
     */
    @Select("SELECT COUNT(*) FROM friend WHERE user_id=#{userId} AND friend_id=#{friendId};")
    int isFriend(Integer userId, Integer friendId);

    /**
     * 添加好友
     */
    @Insert("INSERT INTO friend VALUES " +
            "(null, #{userId}, #{friendId}, #{friendName}, null)," +
            "(null, #{friendId}, #{userId}, #{userName}, null);")
    Integer addFriend(Integer userId, String userName, Integer friendId, String friendName);
}
