package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.system.api.RemoteMmpService;
import com.ruoyi.system.api.domain.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteMmpFallbackFactory implements FallbackFactory<RemoteMmpService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteMmpFallbackFactory.class);

    @Override
    public RemoteMmpService create(Throwable throwable) {
        log.error("管理平台服务调用失败:{}", throwable.getMessage());
        return new RemoteMmpService() {
            @Override
            public GenericsAjaxResult<String> gitLinkLogin(String username, String password) {
                return GenericsAjaxResult.error("刷新gitLink登录信息失败");
            }

            @Override
            public GenericsAjaxResult<String> createGitLinkUser(SysUser sysUser) throws Exception {
                throw new Exception("新增gitLink用户失败:" + throwable.getMessage());
            }

            @Override
            public GenericsAjaxResult<String> resetPwd(SysUser sysUser) throws Exception {
                throw new Exception("修改gitLink用户密码失败:" + throwable.getMessage());
            }

            @Override
            public GenericsAjaxResult<String> resetEmail(SysUser sysUser) throws Exception {
                throw new Exception("修改gitLink用户邮箱失败:" + throwable.getMessage());
            }

            @Override
            public GenericsAjaxResult<String> resetPhoneNum(SysUser sysUser) throws Exception {
                throw new Exception("修改gitLink用户手机号失败:" + throwable.getMessage());
            }

            @Override
            public GenericsAjaxResult<String> deleteGitLinkUser(SysUser sysUser) throws Exception {
                throw new Exception("删除gitLink用户失败:" + throwable.getMessage());
            }
        };
    }
}
