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

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.permissions.api.dto.MenuDto;
import com.sptg.permissions.api.entity.Menu;
import com.sptg.permissions.api.feigns.MenuFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * title: MenuFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description: 菜单对外接口容错处理
 *
 *                  
 *                 
 */
@Component
@Slf4j
public class MenuFeignFallbackFactory implements FallbackFactory<MenuFeign> {

    @Override
    public MenuFeign create(Throwable cause) {
        return new MenuFeign(){
            @Override
            public ResultBean<Menu> getMenuTreeList() {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> insertMenu(MenuDto menuDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> updateMenu(MenuDto menuDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteMenu(MenuDto menuDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

            @Override
            public ResultBean<Menu> getMenuTreeWithRoot() {
                log.error(cause.getMessage(), cause);
                return null;
            }
        };
    }
}
