package com.crunii.micro.feign.client.fallbackfactory;

import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.obs.ObsServiceCodeDto;
import com.crunii.micro.domain.dto.sys.FileBase64;
import com.crunii.micro.feign.client.ObsService;
import com.crunii.micro.feign.client.dto.DownloadFileVo;
import com.crunii.micro.feign.client.dto.FileVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author qiaolin
 * @version 1.0
 * @date 2023/6/5 16:37
 */
@Component
public class ObsServiceFallbackFactory implements FallbackFactory<ObsService> {
    private static final Logger logger = LoggerFactory.getLogger(ObsServiceFallbackFactory.class);

    @Override
    public ObsService create(Throwable cause) {
        logger.error("fallback; exception was: {}", cause.toString());
        logger.error("fallback; reason was: {}", cause.getMessage());
        return new ObsService() {
            @Override
            public Result<String> deleteListFileKey(List<String> fileKey) {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("deleteListFileKey接口调用失败");
                return result;
            }

            @Override
            public Result<String> updateObsServiceCode(List<ObsServiceCodeDto> obsServiceCodeDtos) {
                Result<String> result = new Result();
                result.setSuccess(false);
                result.setMsg("updateObsServiceCode接口调用失败");
                return result;
            }

            @Override public Result<FileVo> feignFileUpload(MultipartFile file) {
                Result<FileVo> result = new Result();
                result.setSuccess(false);
                result.setMsg("fileUpload调用失败");
                return result;
            }

            @Override
            public Result<FileVo> appFileUpload(FileBase64 fileBase64) {
                Result<FileVo> result = new Result();
                result.setSuccess(false);
                result.setMsg("appFileUpload调用失败");
                return result;
            }

            @Override
            public Result<DownloadFileVo> doDownloadFile(Long fileId) {
                Result<DownloadFileVo> result = new Result();
                result.setSuccess(false);
                result.setMsg("doDownloadFile调用失败");
                return result;
            }
        };
    }
}
