package com.vctgo.system.api.factory;

import com.vctgo.common.core.domain.R;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.system.api.RemoteUserService;
import com.vctgo.system.api.domain.SysPlatformDept;
import com.vctgo.system.api.domain.SysPlatformUser;
import com.vctgo.system.api.domain.SysUser;
import com.vctgo.system.api.domain.SysUserTempalte;
import com.vctgo.system.api.domain.dto.StaticsUserPermsDto;
import com.vctgo.system.api.domain.dto.SysUserDto;
import com.vctgo.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

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

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

            @Override
            public R<LoginUser> getVoteUserInfo(String username, String source) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getPlatformUserInfo(String username, String source) {
                return R.fail("获取失败:" + throwable.getMessage());
            }

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

            @Override
            public R<List<SysUser>> getAllUserByTenantId(SysUserDto sysUserDto, String source) {
                return R.fail("获取当前租户下的用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> userList() {
                return R.fail("获取用户信息列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUserTempalte>> userListByTenantIds(String tenantIds) {
                return R.fail("通过租户id获取特定的用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getUserInfo(Long userId) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysPlatformUser> getPlatUserInfo(Long userId) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getSysUserPermissions() {
                return R.fail("通过用户权限列表失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getSysPlatformUserPermissions() {
                return R.fail("通过用户权限列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> judgeUserIsExistPointPerms(StaticsUserPermsDto staticsUserPermsDto, String source) {
                return R.fail("获取指定用户的指定权限数据失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> selectUserAndRoleList(String roleKey) {
                return R.fail("获取指定角色Key的用户Id失败" + throwable.getMessage());
            }

            @Override
            public R<List<SysPlatformDept>> selectProfileUserList() {
                return R.fail("获取内部资料管理获取用户列表失败" + throwable.getMessage());
            }

            @Override
            public R<AjaxResult> getPlatformUserInfo(String userId) {
                return R.fail("根据用户Id获取授权角色失败" + throwable.getMessage());
            }

            @Override
            public R<List<SysPlatformUser>> getUserList(String nickName) {
                return R.fail("获取用户信息:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getAppUserInfo(String account) {
                return R.fail("获取用户信息:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfoByOpenId(String wxCode) {
                return R.fail("获取用户信息:" + throwable.getMessage());
            }

            @Override
            public R<List<String>> getUserName(List<Long> userIds) {
                return R.fail("获取用户昵称信息:" + throwable.getMessage());

            }
        };
    }
}