package com.YuyeTech.TPlat.service.impl;


import com.YuyeTech.TPlat.dataobject.FriendInfo;
import com.YuyeTech.TPlat.repository.FriendInfoRepository;
import com.YuyeTech.TPlat.service.FriendInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FriendInfoServiceImpl implements FriendInfoService {

    @Autowired
    private FriendInfoRepository friendInfoRepository;

    @Override
    public Page<FriendInfo> getFriendUserInfo(Pageable pageable,String userId) {

        return friendInfoRepository.findAllByUserId(pageable,userId);
    }

    @Override
    public FriendInfo findByUserIdAndFriendId(String userId, String friendId) {
        FriendInfo friendInfo = friendInfoRepository.findByUserIdAndFriendId(userId, friendId).orElse(null);
        return friendInfo;
    }

    @Override
    public FriendInfo addFriendInfo(FriendInfo friendInfo) {
        return friendInfoRepository.save(friendInfo);
    }

    @Override
    public void deleteFriendInfo(String userId, String friendId) {
        friendInfoRepository.deleteByUserIdAndFriendId(userId, friendId);
    }

    @Override
    public void deleteById(String id) {
        friendInfoRepository.deleteById(id);
    }

}
