package cn.reghao.tnb.user.app.rpc;

import cn.reghao.tnb.user.api.dto.ContactDetail;
import cn.reghao.tnb.user.api.dto.UserInfo;
import cn.reghao.tnb.user.api.iface.UserContactService;
import cn.reghao.tnb.user.app.db.mapper.UserContactMapper;
import cn.reghao.tnb.user.app.service.ContactService;
import cn.reghao.tnb.user.app.service.UserProfileService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author reghao
 * @date 2023-11-30 11:06:35
 */
@DubboService
@Service
public class UserContactServiceImpl implements UserContactService {
    private final UserContactMapper userContactMapper;
    private final ContactService contactService;
    private final UserProfileService userProfileService;

    public UserContactServiceImpl(UserContactMapper userContactMapper, ContactService contactService,
                                  UserProfileService userProfileService) {
        this.userContactMapper = userContactMapper;
        this.contactService = contactService;
        this.userProfileService = userProfileService;
    }

    @Override
    public void setOnline(long userId, boolean online) {
        userContactMapper.updateContactStatus(userId, online);
    }

    @Override
    public List<Long> getOnlineFriends(long userId) {
        return userContactMapper.findOnlineFriends(userId);
    }

    @Override
    public ContactDetail getContactDetail(long userId) {
        return contactService.getContactDetail(userId);
    }

    @Override
    public UserInfo getUserInfo(long userId) {
        return userProfileService.getUserInfo(userId);
    }
}
