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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ExcelResultEnum;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.estate.api.dto.ResidentialDto;
import com.sptg.estate.api.entity.Residential;
import com.sptg.estate.api.feigns.ResidentialFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: ResidentialFallbackFactory
 * package: com.sptg.estate.api.feigns.fallback
 * description: 小区 服务接口容错处理类
 *
 *             
 *                
 */
@Component
@Slf4j
public class ResidentialFeignFallbackFactory implements FallbackFactory<ResidentialFeign> {

    @Override
    public ResidentialFeign create(Throwable cause) {
        return new ResidentialFeign() {
            @Override
            public ResultBean<Page<Residential>>  showResidentialList(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Residential> addResidential(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

            @Override
            public ResultBean<Boolean> updateResidential(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteResidential(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> trashOrRecover(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteResidentialList(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Residential> findListByPosition(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Page<Residential>> statisticsUserCountList(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<Residential> getStatisticsUserCountList(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public List<Residential> getByOrgIdList(List<Long> idList) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(0);
            }

            @Override
            public ResultBean<Long> statisticsUserCount(String orgPosition) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> importResidentialList(List<ResidentialDto> list) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ExcelResultEnum.ERROR);
            }

            @Override
            public ResultBean<Map<String, Integer>> getResidentialAccount(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Residential> getByRegionArea(Residential residential) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public Integer getResidentialCount(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public Long getUnitCount(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return 0L;
            }

            @Override
            public List<Map<String, Object>> statisticsCityCountList(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public int getResidentialByNameAndRegion(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public Residential findResidentialByNumber(String residentialNumber) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public long getUserCountForRegionAuthorize(String orgPosition) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public ResultBean<Boolean> updateResidentialEntity(Residential residential) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Residential> getListByCondition(ResidentialDto residentialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public boolean updateEntity(Residential residential) {
                log.error(cause.getMessage(),cause);
                return false;
            }

            @Override
            public List<Residential> getListByLikeName(ResidentialDto dto) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public Residential getByOldId(String oldId) {
                log.error(cause.getMessage(),cause);
                return null;
            }
//            @Override
//            public ResultBean<Residential> getResidentialList(ResidentialDto residentialDto) {
//                log.error(cause.getMessage(),cause);
//                return null;
//            }
        };
    }
}
