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.RegionAuthorizeDto;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.entity.Region;
import com.sptg.permissions.api.entity.RegionAuthorize;
import com.sptg.permissions.api.feigns.RegionAuthorizeFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: RegionAuthorizeFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description: 区域授权-容错处理
 *
 *                  
 *                 
 */
@Component
@Slf4j
public class RegionAuthorizeFeignFallbackFactory implements FallbackFactory<RegionAuthorizeFeign> {
    @Override
    public RegionAuthorizeFeign create(Throwable cause) {
        return new RegionAuthorizeFeign(){
            @Override
            public List<Region> getAuthorizeRegionList(String position) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }

            @Override
            public List<Region> getAuthorizeRegion(RegionAuthorizeDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }

            @Override
            public Page<RegionAuthorize> pagingQuery(PageBean<RegionAuthorize,RegionAuthorizeDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return pageBean;
            }

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

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

            @Override
            public List<Organization> getAuthorizeOrgList(RegionAuthorizeDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }

            @Override
            public List<Organization> getAuthorizeOrgListTwo(RegionAuthorizeDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(0);
            }

            @Override
            public Page<Organization> pagingQueryAuthorizeOrg(PageBean<RegionAuthorize,RegionAuthorizeDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return new Page<>(pageBean.getCurrent(),pageBean.getSize());
            }
        };
    }
}
