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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.permissions.api.dto.RoleDto;
import com.sptg.permissions.api.entity.Role;
import com.sptg.permissions.api.feigns.RoleFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * title: RoleFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description: 角色对外服务接口容错处理
 *
 *                  
 *                 
 */
@Component
@Slf4j
public class RoleFeignFallbackFactory implements FallbackFactory<RoleFeign> {

    @Override
    public RoleFeign create(Throwable cause) {
        return new RoleFeign(){
            @Override
            public ResultBean<Page> pagingQuery(PageBean<Role, RoleDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> addEntity(RoleDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public Role getById(Long id) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public ResultBean<Boolean> updateEntity(RoleDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteEntity(RoleDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<Role> getListByOrgId(Long orgId) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }

            @Override
            public List<Role> getListByAccountId(Long accountId) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }
        };
    }
}
