package ink.wgink.module.file.service;

import ink.wgink.exceptions.FileException;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.module.file.enums.UploadTypeEnum;
import ink.wgink.pojo.pos.FilePO;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * @ClassName: IDefaultFileService
 * @Description: 默认文件业务
 * @Author: wanggeng
 * @Date: 2021/10/17 10:18 上午
 * @Version: 1.0
 */
public interface IDefaultFileService {

    /**
     * 上传文件
     *
     * @param token          app的Token
     * @param uploadFile     上传文件
     * @param uploadTypeEnum 上传文件类型
     * @param params         参数
     * @throws SystemException
     */
    void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) throws SystemException;

    /**
     * 文件上传
     *
     * @param userId         用户ID
     * @param uploadFile
     * @param uploadTypeEnum
     * @param params
     */
    void uploadFileByUserId(String userId, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params);

    /**
     * 物理删除文件
     *
     * @param filePOs 要删除的文件列表
     */
    void deleteFile(List<FilePO> filePOs);

    /**
     * 保存文件信息
     *
     * @param token
     * @param fileName
     * @param uploadPath
     * @param uploadFileName
     * @param fileType
     * @param fileSize
     */
    void saveUploadFileInfo(String token, String fileName, String uploadPath, String uploadFileName, String fileType, long fileSize, Map<String, Object> params);

    /**
     * 保存文件信息
     *
     * @param userId
     * @param fileName
     * @param uploadPath
     * @param uploadFileName
     * @param fileType
     * @param fileSize
     * @param params
     */
    void saveUploadFileInfoByUserId(String userId, String fileName, String uploadPath, String uploadFileName, String fileType, long fileSize, Map<String, Object> params);

    /**
     * 获取上传文件路径
     *
     * @param baseUploadPath
     * @param uploadTypeEnum
     * @param fileType
     * @return
     * @throws FileException
     */
    String getUploadPath(String baseUploadPath, UploadTypeEnum uploadTypeEnum, String fileType) throws FileException;

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

    /**
     * 下载文件
     *
     * @param request
     * @param response
     * @param filePO
     * @param isOpen
     * @param canRange
     * @return 是否下载完成
     */
    boolean downLoadFile(HttpServletRequest request, HttpServletResponse response, FilePO filePO, boolean isOpen, boolean canRange);

}
