package ink.wgink.module.file.service;

import com.alibaba.fastjson.JSONObject;
import ink.wgink.module.file.enums.UploadTypeEnum;
import ink.wgink.module.file.pojo.dtos.FileDTO;
import ink.wgink.module.file.pojo.dtos.FileInfoDTO;
import ink.wgink.module.file.pojo.vos.FileVO;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.pos.FilePO;
import ink.wgink.pojo.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";
    /**
     * 文件MD5值开头
     */
    public static final String FILE_MD5_PREFIX = "MD5:";
    /**
     * 文件引用值开头
     */
    public static final String FILE_REF_PREFIX = "REF:";

    /**
     * 保存文件
     *
     * @param userId 用户ID
     * @param fileVO 文件对象
     * @return 文件ID
     */
    String saveFileByUserId(String userId, FileVO fileVO);

    /**
     * 删除记录
     *
     * @param ids
     */
    @Deprecated
    void remove(String ids);

    /**
     * 删除记录
     *
     * @param ids
     */
    void remove(List<String> ids);

    /**
     * 删除记录和文件
     *
     * @param ids
     */
    @Deprecated
    void delete(String ids);

    /**
     * 删除记录和文件
     *
     * @param ids
     */
    void delete(List<String> ids);

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

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

    /**
     * 文件上传
     *
     * @param userId
     * @param uploadFile
     * @param uploadTypeEnum
     * @param params
     * @return
     */
    String uploadSingleByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params);

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

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

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

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

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

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

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

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

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

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

    /**
     * 通过ID列表获取文件列表
     *
     * @param idList
     * @return
     */
    List<FilePO> listPO(List<String> idList);

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

}
