package com.vctgo.system.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.vctgo.common.core.domain.R;
import com.vctgo.system.api.RemoteFileService;
import com.vctgo.system.api.domain.FileInfo;
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 vctgo
 */
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);

    @Override
    public RemoteFileService create(Throwable throwable) {
        log.error("文件服务调用失败:{}", throwable.getMessage());
        return new RemoteFileService() {
            @Override
            public R<FileInfo> upload(MultipartFile file) {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R mkdirByTenantId(Long tenantId, String parentId, String dirName) {
                return R.fail("云盘通过租户Id创建文件夹失败:" + throwable.getMessage());
            }

            @Override
            public R mkdir(String parentId, String dirName) {
                return R.fail("云盘创建文件夹失败:" + throwable.getMessage());
            }

            @Override
            public R updateFileServiceIdAndServiceNameByIds(String serviceName, String serviceId, String ids) {
                return R.fail("更新文件状态信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<FileInfo>> selectUrlByIds(String ids) {
                return R.fail("通过文件集获取信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> minioDelete(Long[] ids) {
                return R.fail("通过文件集删除文件失败:" + throwable.getMessage());
            }

            @Override
                public R pageFileInfoNeglectTenant(String fileInfo,Integer pageNum ,Integer pageSize) {
                return R.fail("忽略租户的云盘获取列表失败");
            }

            @Override
            public R<JSONObject> innerListFile(String fileInfo, Integer pageNum, Integer pageSize) {
                return null;
            }

            @Override
            public R<String> mkdirByFileInfo(String parentId, String fileInfo) {
                return null;
            }

            @Override
            public R<String> mkdirByTenantAndFile(Long tenantId, String parentId, String fileInfo) {
                return null;
            }

            @Override
            public R updateFileInfo(String fileId, String fileInfo) {
                return null;
            }

            @Override
            public R innerMoveFileByIds(String ids, String toParentId) {
                return null;
            }

            @Override
            public R innerDeleteFileByIds(String fileInfo) {
                return null;
            }

            @Override
            public R innerHideFileByIds(String fileInfoList) {
                return null;
            }

            @Override
            public R innerRecoverFileByIds(String recoverFileList) {
                return null;
            }

            @Override
            public R initMkdirByTenantId(Long tenantId, String serviceName, String fileName) {
                return R.fail("租户创建文件资源管理文件夹失败");
            }

            @Override
            public R deleteFileByFileIds(String fileIds) {
                return R.fail("通过文件Id逻辑删除文件、文件夹失败");
            }

            @Override
            public R innerUpload(MultipartFile file) {
                return R.fail("内部上传文件失败");
            }
        };
    }
}
