package ink.wgink.login.oauth2.client.service.appsign;

import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.app.IAppSignBaseService;
import ink.wgink.login.oauth2.client.remote.appsign.IAppSignRemoteService;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.properties.ApiPathProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppSignServiceImpl implements IAppSignBaseService {
    @Autowired
    private ApiPathProperties apiPathProperties;
    @Autowired
    private IAppSignRemoteService appSignRemoteService;

    @Override
    public String userIdSign(String userId) throws Exception {
        if (StringUtils.isBlank(userId)) {
            throw new ParamsException("userId不能为空");
        }
        SuccessResultData<String> successResultData = appSignRemoteService.getTokenByUserId(apiPathProperties.getUserCenter(), OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(), userId);
        return successResultData.getData();
    }
}
