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.common.core.constant.OperationConstant;
import com.sptg.permissions.api.dto.DeviceAuthorizeDto;
import com.sptg.permissions.api.dto.RegionDto;
import com.sptg.permissions.api.entity.DeviceAuthorize;
import com.sptg.permissions.api.entity.Region;
import com.sptg.permissions.api.feigns.DeviceAuthorizeFeign;
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: DeviceAuthorizeFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description:
 *
 *
 *
 */
@Slf4j
@Component
public class DeviceAuthorizeFeignFallbackFactory implements FallbackFactory<DeviceAuthorizeFeign> {

    @Override
    public DeviceAuthorizeFeign create(Throwable cause) {
        return new DeviceAuthorizeFeign(){
            @Override
            public Page<DeviceAuthorize> pagingQueryDy(PageBean<DeviceAuthorize,DeviceAuthorizeDto> pageBean) {
                log.error(cause.getMessage(),cause);
                return pageBean;
            }

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

            @Override
            public Page<DeviceAuthorize> specialDevicesPagingQuery(PageBean<DeviceAuthorize, DeviceAuthorizeDto> pageBean) {
                log.error(cause.getMessage(),cause);
                return pageBean;
            }

            @Override
            public Page<Region> pagingQueryRegion(PageBean<Region,RegionDto> pageBean) {
                log.error(cause.getMessage(),cause);
                return pageBean;
            }

            @Override
            public ResultBean<Map<String,Long>> getDeviceCoverAccount(DeviceAuthorizeDto dto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public Long getDeviceCount(DeviceAuthorizeDto dto) {
                log.error(cause.getMessage(),cause);
                return 0L;
            }

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

            @Override
            public Map<String, Object> getDeviceCountForInstallPathType(DeviceAuthorizeDto dto) {
                log.error(cause.getMessage(),cause);
                return  null;
            }

            @Override
            public List<Map<String, Object>> getDeviceCountForMonth(DeviceAuthorizeDto dto) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public List<String> getDeviceAuthorizeOrgList(String serialNumber) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(0);
            }

            @Override
            public List<Long> getDeviceIdListByOrg(String orgPosition) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(0);
            }
        };
    }

}
