package com.wecloud.im.service.impl;

import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.wecloud.dispatch.extend.ActionRequest;
import com.wecloud.dispatch.util.ActionRequestHolder;
import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient;
import com.wecloud.im.service.ContextService;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService;

/**
 * 请求上下文服务 impl
 * @Author luozh
 * @Date 2022年04月02日 14:56
 * @Version 1.0
 */
@Service
public class ContextServiceImpl implements ContextService {


    @Autowired
    @Lazy
    private ImClientService imClientService;

    @Autowired
    private ImApplicationService imApplicationService;

    @Override
    public ImClient getImClientIfNotNullOrThrow() {

        ImClient currentClient = imClientService.getCurrentClient();

        if (currentClient == null) {
            throw new BusinessException("当前用户登录信息失效");
        }
        return currentClient;
    }

    @Override
    public ImApplication getImApplicationIfNotNullOrThrow(Long appId) {
        ImApplication imApplication = imApplicationService.getCacheById(appId);
        if (imApplication == null) {
            throw new BusinessException("查无应用信息");
        }
        return imApplication;
    }
}
