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.AppPackageDto;
import com.sptg.permissions.api.entity.AppPackage;
import com.sptg.permissions.api.feigns.AppPackageFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * title: AppPackageFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description:app安装包-容错处理
 *
 *
 *
 */
@Component
@Slf4j
public class AppPackageFallbackFactory implements FallbackFactory<AppPackageFeign> {

    @Override
    public AppPackageFeign create(Throwable cause) {

        return new AppPackageFeign() {
            @Override
            public ResultBean<Page> pagingQuery(PageBean<AppPackage, AppPackageDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

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

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

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

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

            @Override
            public AppPackage getNewestVersion(AppPackage appPackage) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public AppPackage appPackageCheck(AppPackage appPackage) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public ResultBean<AppPackage> getListByLikeVersion(AppPackageDto appPackageDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<AppPackage> getListByModelAndFactory(String model, String factory) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public boolean checkPackageNameIsExist(String packageName) {
                log.error(cause.getMessage(), cause);
                return false;
            }

            @Override
            public boolean setRestore(List<String> appIds) {
                log.error(cause.getMessage(), cause);
                return false;
            }

            @Override
            public AppPackage getRestore(String model, String factory) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public boolean checkVersionIsExist(String packageName) {
                log.error(cause.getMessage(), cause);
                return false;
            }
        };
    }
}
