package com.hdkj.lt.feign.fallback;

import com.alibaba.fastjson.JSON;
import com.hdkj.hussar.ApiResponse;
import com.hdkj.lt.feign.IFileApiClient;
import com.hdkj.lt.modle.FileInfoDTO;
import com.hdkj.lt.modle.FileRequest;
import com.hdkj.lt.modle.FileUploadDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description
 * @Author wcx
 * @Date 2025/6/3 15:53
 * @Version 1.0
 */
@Slf4j
@Component
public class FileApiClientFallBack implements FallbackFactory<IFileApiClient> {

    @Override
    public IFileApiClient create(Throwable cause) {
        return new IFileApiClient() {
            @Override
            public ApiResponse<FileInfoDTO> upload(FileRequest request) {
                log.error("request params: {}", JSON.toJSONString(request));
                return ApiResponse.fail(String.format("远程调用文件上传服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<byte[]> getFileById(FileRequest request) {
                log.error("request params: {}", JSON.toJSONString(request));
                return ApiResponse.fail(String.format("远程调用文件下载服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<List<FileUploadDTO>> listObject(String fileDir) {
                log.error("request params: {}", fileDir);
                return ApiResponse.fail(String.format("远程调用配电云主站附件查询服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<byte[]> getObject(String objectName) {
                log.error("request params: {}", objectName);
                return ApiResponse.fail(String.format("远程调用配电云主站附件下载服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<String> removeObject(String objectName) {
                log.error("request params: {}", objectName);
                return ApiResponse.fail(String.format("远程调用配电云主站附件删除服务异常：%s", cause.getMessage()));
            }
        };
    }
}
