package com.m2pool.system.api.factory;

import com.m2pool.common.core.Result.R;
import com.m2pool.system.api.RemoteUserService;
import com.m2pool.system.api.entity.SysUser;
import com.m2pool.system.api.entity.SysUserLeveDate;
import com.m2pool.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;

/**
 * @Description 用户服务降级处理
 * @Date 2024/6/11 15:48
 * @Author dy
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

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


    @Override
    public RemoteUserService create(Throwable cause) {
        log.error("用户服务调用失败：{}",cause.getMessage());

        return new RemoteUserService(){

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

            @Override
            public R<Boolean> updateUserInfo(SysUser sysUser) {
                return R.fail("修改用户失败:" + cause.getMessage());
            }

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

            @Override
            public R<Boolean> resetPwdByEmail(SysUser sysUser) {
                return R.fail("重置用户密码失败:" + cause.getMessage());
            }

            @Override
            public R<SysUserLeveDate> userLevel(Long userId) {
                return  R.fail("获取用户会员信息失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> userLevelup(SysUserLeveDate user, String source) {
                return R.fail("用户升级失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> checkGoogleCode(Long code, String source) {
                return R.fail("谷歌验证器校验失败:" + cause.getMessage());
            }

            @Override
            public R<List<SysUser>> getCSList() {
                return R.fail("客服列表获取失败:" + cause.getMessage());
            }

        };
    }
}
