package org.wfc.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.wfc.common.core.domain.LoginUser;
import org.wfc.common.core.domain.R;
import org.wfc.system.api.RemoteUserService;
import org.wfc.system.api.domain.SysUser;

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

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("User service call failed:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser<SysUser>> getUserInfo(String username, String source)
            {
                return R.fail("Failed to get user:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("Failed to register user:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> recordUserLogin(SysUser sysUser, String source)
            {
                return R.fail("Failed to record user login information:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> deviceJob() {
                return R.fail("Failed to record device information:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> settingJob() {
                return R.fail("Omada setting job error:" + throwable.getMessage());
            }

            @Override
            public R<String> testJob() {
                return R.fail("Omada test job error:" + throwable.getMessage());
            }
        };
    }
}
