package cn.sikey.mcdisk.service;

import cn.sikey.mcdisk.controller.app.familycloud.vo.InviteFamilyMemberListRespVO;
import cn.sikey.mcdisk.controller.app.familycloud.vo.InviteFamilyMemberRespVO;
import cn.sikey.mcdisk.convert.OauthConvert;
import cn.sikey.mcdisk.dal.dataobject.InviteFamilyMemberDO;
import cn.sikey.mcdisk.dal.mysql.InviteFamilyMemberMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: nelson
 * @Date: 2025/6/5
 * @Description: 邀请用户加入家庭成员
 */
@Service
@Slf4j
public class InviteFamilyMemberServiceImpl extends AbstractMcdiskService implements InviteFamilyMemberService {

    @Resource
    private InviteFamilyMemberMapper inviteFamilyMemberMapper;

    /**
     * 查询app用户认证
     *
     * @param userId   用户id
     * @param deviceId 设备编码
     * @return
     */
    @Override
    public InviteFamilyMemberRespVO queryAppOauth(String userId, String deviceId) {
        InviteFamilyMemberDO queryAppOauth = inviteFamilyMemberMapper.queryAppOauth(userId, deviceId);
        return OauthConvert.INSTANCE.convertInviteFamilyMemberRespVO(queryAppOauth);
    }

    /**
     * 查询app用户认证列表
     *
     * @param userIdList    用户id列表
     * @param deviceId      设备编码
     * @return InviteFamilyMemberListRespVO
     */
    @Override
    public InviteFamilyMemberListRespVO queryAppOauthList(List<String> userIdList, String deviceId) {
        List<InviteFamilyMemberDO> queryAppOauthList = inviteFamilyMemberMapper.queryAppOauthList(userIdList, deviceId);
        InviteFamilyMemberListRespVO respV0 = new InviteFamilyMemberListRespVO();
        List<String> strList = new ArrayList<>();
        for (InviteFamilyMemberDO item : queryAppOauthList) {
            strList.add(item.getUserId());
        }
        respV0.setUserIdList(strList);
        return respV0;
    }


    /**
     * 根据用户Id列表批量删除保存邀请用户加入家庭成员
     *
     * @param userIdList    用户id列表
     * @param deviceId      设备编码
     *
     */
    @Override
    public void deleteInviteFamilyMembers(List<String> userIdList, String deviceId) {
       int num = inviteFamilyMemberMapper.deleteInviteFamilyMembers(userIdList, deviceId);
       log.info("[删除保存邀请用户加入家庭成员]deleteInviteFamilyMember num：{}", num);
    }

    /**
     * 保存邀请用户加入家庭成员
     *
     * @param inviteFamilyMemberDO 邀请用户加入家庭成员
     * @return
     */
    @Override
    public void saveInviteFamilyMember(InviteFamilyMemberDO inviteFamilyMemberDO) {
        inviteFamilyMemberMapper.insert(inviteFamilyMemberDO);
    }
}
