package com.sptg.permissions.api.feigns.fallback;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.permissions.api.dto.AccountDto;
import com.sptg.permissions.api.dto.LoginDto;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.feigns.AccountAuthenticationFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * title: AccountAuthenticationFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description: 认证授权相关接口-容错处理
 *
 *                  
 *                 
 */
@Component
@Slf4j
public class AccountAuthenticationFeignFallbackFactory implements FallbackFactory<AccountAuthenticationFeign> {

    @Override
    public AccountAuthenticationFeign create(Throwable cause){
        return new AccountAuthenticationFeign() {
            @Override
            public Account authLogin(LoginDto loginDto) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public ResultBean<Account> login(LoginDto loginDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Account> oauthLogin(LoginDto loginDto) {
                return null;
            }

            @Override
            public Account reload(Serializable id) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public ResultBean<Account> getByOpenid(String openid) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> bindOpenid(AccountDto accountDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
