package com.persagy.dmp.file.client;

import cn.hutool.extra.spring.SpringUtil;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import com.persagy.dmp.file.model.FileInfo;
import com.persagy.dmp.file.model.FileRequestData;
import com.persagy.dmp.file.model.UploadMes;

import java.util.List;

/**
 * 文件管理Client门面
 * @author Charlie Yu
 * @date 2021-05-15
 */
public class FileClientFacade {

    private static FileManageClient client = SpringUtil.getBean(FileManageClient.class);

    /**
     * 新增
     * @param fileInfo
     * @return
     */
    public static FileInfo insert(FileInfo fileInfo) {
        CommonResult<FileInfo> result = client.insert(fileInfo);
        return ResultHelper.getContent(result);
    }

    /**
     * 修改
     * @param fileInfo
     * @return
     */
    public static FileInfo update(FileInfo fileInfo) {
        CommonResult<FileInfo> result = client.update(fileInfo);
        return ResultHelper.getContent(result);
    }

    /**
     * 删除
     * @param fileId
     */
    public static void delete(String fileId) {
        CommonResult<String> result = client.delete(fileId);
        ResultHelper.getContent(result);
    }

    /**
     * 查询
     * @param fileId
     * @return
     */
    public static FileInfo load(String fileId) {
        CommonResult<FileInfo> result = client.load(fileId);
        return ResultHelper.getContent(result);
    }
    /**
     * 查询
     * @param fileMd5
     * @return
     */
    public static List<FileInfo> queryByFileMd5(String fileMd5) {
        CommonResult<List<FileInfo>> result = client.queryByFileMd5(fileMd5);
        return ResultHelper.getContent(result);
    }

    /***
     * Description: 获取文件上传信息-单个文件
     * @param requestData : 请求参数
     * @return : com.persagy.dmp.common.model.response.CommonResult<com.persagy.dmp.file.model.UploadMes>
     * @author : lijie
     * @date :2021/11/9 10:18
     * Update By lijie 2021/11/9 10:18
     */
    public static CommonResult<UploadMes> initChunkUploadPrototype(String groupCode, String projectId, String appId,
                                                                   String userId, FileRequestData requestData){
        return client.initChunkUpload(groupCode, projectId, appId, userId, requestData);
    }

    /***
     * Description: 获取文件上传信息-单个文件
     * @param requestData : 请求参数
     * @return : com.persagy.dmp.common.model.response.CommonResult<com.persagy.dmp.file.model.UploadMes>
     * @author : lijie
     * @date :2021/11/9 10:18
     * Update By lijie 2021/11/9 10:18
     */
    public static CommonResult<UploadMes> composeFilePrototype(String groupCode, String projectId, String appId,
                                                                   String userId, FileRequestData requestData){
        return client.composeFile(groupCode, projectId, appId, userId, requestData);
    }

    /***
     * Description: 获取文件上传信息-单个文件
     * @param requestData : 请求参数
     * @return : com.persagy.dmp.common.model.response.CommonResult<com.persagy.dmp.file.model.UploadMes>
     * @author : lijie
     * @date :2021/11/9 10:18
     * Update By lijie 2021/11/9 10:18
     */
    public static CommonResult<UploadMes> initSingleUploadPrototype(String groupCode, String projectId, String appId,
                                                                    String userId, FileRequestData requestData){
        return client.initSingleUpload(groupCode, projectId, appId, userId, requestData);
    }
    /***
     * Description: 获取文件上传信息-单个文件
     * @param requestData : 请求参数
     * @return : com.persagy.dmp.common.model.response.CommonResult<com.persagy.dmp.file.model.UploadMes>
     * @author : lijie
     * @date :2021/11/9 10:18
     * Update By lijie 2021/11/9 10:18
     */
    public static CommonResult<FileInfo> initFileDownloadPrototype(FileRequestData requestData){
        return client.initFileDownload(requestData);
    }



}
