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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.ad.api.dto.AdMaterialDto;
import com.sptg.ad.api.entity.AdMaterial;
import com.sptg.ad.api.feigns.AdMaterialFeign;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import feign.hystrix.FallbackFactory;
import javafx.scene.paint.Material;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * title: AdMaterialFeignFallbackFactory
 * package: com.sptg.ad.api.feigns.fallback
 * description: 广告素材接口容错处理
 *
 *
 *
 */
@Slf4j
@Component
public class AdMaterialFeignFallbackFactory implements FallbackFactory<AdMaterialFeign> {
    @Override
    public AdMaterialFeign create(Throwable cause) {
        return new AdMaterialFeign() {
            @Override
            public ResultBean<Page<AdMaterial>> showAdMaterialList(AdMaterialDto adMaterialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> addAdMaterial(AdMaterial adMaterial) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteAdMaterial(String ids) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public AdMaterial findAdMaterialById(Long id) {
                log.error(cause.getMessage(),cause);
                AdMaterial adMaterial = new AdMaterial();
                adMaterial.setMaterialName("找不到id为 "+id+" 的广告素材");
                return new AdMaterial();
            }

            @Override
            public ResultBean<Boolean> deleteAdMaterialList(AdMaterialDto adMaterialDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
