package cn.wisenergy.service.Manager;

import cn.wisenergy.mapper.UserDataInfoMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.User;
import cn.wisenergy.model.app.UserDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserDataInfoManager {

    @Autowired
    private UserDataInfoMapper userDataInfoMapper;

    @Autowired
    private UsersMapper usersMapper;

    //记录用户设置邀请码的行为数据

    public boolean addUserSetBeInvitedCodeDoc(String userId , String invitedUserId){

        if (null != userId && null != invitedUserId){

            User userByUserId = usersMapper.getUserByUserId(userId);
            User inviteduserByUserId = usersMapper.getUserByUserId(invitedUserId);

            if (null != userByUserId && null != inviteduserByUserId){
                //用户自身的邀请码
                String inviteCode = userByUserId.getInviteCode();
                //推荐人的邀请码
                String beInvitedCode = inviteduserByUserId.getInviteCode();
                UserDataInfo userDataInfo = new UserDataInfo();
                userDataInfo.setUserId(userId);
                userDataInfo.setInviteCode(inviteCode);
                userDataInfo.setBeInvitedCode(beInvitedCode);
                userDataInfo.setLevelStatus(0);
                userDataInfoMapper.add(userDataInfo);
                return true;
            }
        }
        return false;
    }
}
