package com.cm.common.plugin.service.file;

import com.alibaba.fastjson.JSONObject;
import com.cm.common.enums.UploadTypeEnum;
import com.cm.common.exception.FileException;
import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SearchException;
import com.cm.common.exception.base.SystemException;
import com.cm.common.plugin.pojo.dtos.file.FileInfoDTO;
import com.cm.common.pojo.ListPage;
import com.cm.common.pojo.dtos.FileDTO;
import com.cm.common.pojo.pos.FilePO;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: IFileService
 * @Description: 文件处理
 * @Author: WangGeng
 * @Date: 2019/3/10 7:05 PM
 * @Version: 1.0
 **/
public interface IFileService {

    /**
     * 文件类型
     */
    String UPLOAD_FILE_TYPE = "1";
    /**
     * 图片类型
     */
    String UPLOAD_IMAGE_TYPE = "2";
    /**
     * 视频类型
     */
    String UPLOAD_VIDEO_TYPE = "3";
    /**
     * 音频类型
     */
    String UPLOAD_AUDIO_TYPE = "4";
    /**
     * 读取流大小 1M
     */
    int INPUT_STREAM_SIZE = 1048576;

    /**
     * uEditor action
     */
    String UEDITOR_ACTION = "action";
    /**
     * uEditor config
     */
    String UEDITOR_CONFIG = "config";
    /**
     * uEditor 图片
     */
    String UEDITOR_UPLOAD_IMAGE = "uploadimage";
    /**
     * uEditor 视频
     */
    String UEDITOR_UPLOAD_VIDEO = "uploadvideo";
    /**
     * uEditor 文件
     */
    String UEDITOR_UPLOAD_FILE = "uploadfile";
    /**
     * uEditor 图片列表
     */
    String UEDITOR_LIST_IMAGE = "listimage";
    /**
     * uEditor 文件列表
     */
    String UEDITOR_LIST_FILE = "listfile";

    /**
     * 文件分页列表
     *
     * @param page
     * @return
     * @throws SearchException
     */
    SuccessResultList<List<FileInfoDTO>> listPageFileInfo(ListPage page) throws SearchException;

    /**
     * 删除记录
     *
     * @param ids
     * @throws RemoveException
     */
    void removeFile(String ids) throws RemoveException;

    /**
     * 删除记录和文件
     *
     * @param ids
     * @throws RemoveException
     */
    void deleteFile(String ids) throws RemoveException;

    /**
     * 文件上传
     *
     * @param uploadFile
     * @param uploadTypeEnum
     * @param params
     * @return
     * @throws SystemException
     */
    SuccessResultData<String> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;

    /**
     * 文件上传
     *
     * @param token
     * @param uploadFile
     * @param uploadTypeEnum
     * @param params
     * @return
     * @throws SystemException
     * @throws IOException
     */
    SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;

    /**
     * 文件上传
     *
     * @param token
     * @param uploadFile
     * @param uploadTypeEnum
     * @param params
     * @return
     * @throws SystemException
     */
    FileDTO uploadSingleForFileDTO(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;

    /**
     * 文件下载
     *
     * @param response
     * @param params
     * @throws FileException
     */
    void downLoadFile(HttpServletResponse response, Map<String, Object> params) throws FileException;

    /**
     * 文件下载
     *
     * @param request
     * @param response
     * @param params
     * @throws FileException
     */
    void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map<String, Object> params) throws FileException;

    /**
     * 文件下载
     *
     * @param request
     * @param response
     * @param params
     * @param canRange 开启断点续传
     * @throws FileException
     */
    void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map<String, Object> params, boolean canRange) throws FileException;

    /**
     * 百度富文本编辑器
     *
     * @param file
     * @param request
     * @param params
     * @return
     * @throws SystemException
     * @throws IOException
     */
    JSONObject uEditor(MultipartFile file, HttpServletRequest request, Map<String, Object> params) throws SystemException, IOException;

    /**
     * wangEditor上传文件
     *
     * @param image
     * @param image1
     * @param params
     * @return
     */
    JSONObject wangEditorImage(MultipartFile image, UploadTypeEnum image1, Map<String, Object> params);

    /**
     * 获取文件详情
     *
     * @param params
     * @return
     * @throws SearchException
     */
    FilePO getFile(Map<String, Object> params) throws SearchException;

    /**
     * 保存导入Excel异常文件信息
     *
     * @param fileName
     * @param uploadPath
     * @param fileSize
     * @param params
     */
    void saveUploadErrorExcelFileInfo(String fileName, String uploadPath, long fileSize, Map<String, Object> params);

    /**
     * 获取导入Excel异常文件路径
     *
     * @return
     */
    String getUploadExcelErrorPath();

    /**
     * 通过文件ID获取ID列表
     *
     * @param idList
     * @return
     * @throws SearchException
     */
    List<FileDTO> listFileByFileId(List<String> idList) throws SearchException;

    /**
     * 校验视频长度是否符合
     *
     * @param uploadFile
     * @param maxDuration
     * @throws SystemException
     */
    void checkVideoDurationAllow(MultipartFile uploadFile, long maxDuration) throws SystemException;

    /**
     * 校验音频长度是否符合
     *
     * @param uploadFile
     * @param maxDuration
     * @throws SystemException
     */
    void checkAudioDurationAllow(MultipartFile uploadFile, long maxDuration) throws SystemException;
}
