package com.flossom.system.api.factory;

import com.flossom.common.core.domain.LoginBody;
import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.RegisterBody;
import com.flossom.common.core.domain.entity.WxUserMember;
import com.flossom.system.api.RemoteAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户服务降级处理
 *
 * @author flossom
 */
@Component
public class RemoteAuthFallbackFactory implements FallbackFactory<RemoteAuthService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteAuthFallbackFactory.class);

    @Override
    public RemoteAuthService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteAuthService() {

            @Override
            public R<Map<String, String>> login(LoginBody form) {
                return R.fail("用户登录失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<String, String>> wxLogin(WxUserMember form) {
                return R.fail("用户登录失败:" + throwable.getMessage());
            }

            @Override
            public R<?> register(RegisterBody registerBody) {
                return R.fail("用户注册失败:" + throwable.getMessage());
            }
        };
    }
}
