package com.inspect.system.base.factory;

import com.inspect.base.core.domain.Response;
import com.inspect.system.base.RemoteUserService;
import com.inspect.system.base.domain.SysUser;
import com.inspect.system.base.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
   private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

   public RemoteUserService create(final Throwable throwable) {
      log.error("用户服务调用失败:{}", throwable.getMessage());
      return new RemoteUserService() {
         public Response<LoginUser> getUserInfo(String username, String source) {
            return Response.fail("获取用户失败:" + throwable.getMessage());
         }

         public Response<Boolean> registerUserInfo(SysUser sysUser, String source) {
            return Response.fail("注册用户失败:" + throwable.getMessage());
         }
      };
   }
}
