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.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.util.List;
import java.util.Map;

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

    /**
     * 保存文件
     *
     * @param fileVO
     */
    void saveFile(FileVO fileVO);

    /**
     * 保存文件
     *
     * @param userId
     * @param fileVO
     * @return
     */
    String saveFileByUserId(String userId, FileVO fileVO);

    /**
     * 上传文件
     *
     * @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 ids
     */
    void remove(List<String> ids);

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

    /**
     * 物理删除
     *
     * @param params
     */
    void delete(List<String> ids);

    /**
     * 保存文件信息
     *
     * @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 request
     * @param response
     * @param params
     * @param canRange
     */
    boolean 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);

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

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

    /**
     * 文件列表
     *
     * @param idList
     * @return
     */
    List<FileDTO> list(List<String> idList);

    /**
     * 文件列表
     *
     * @param idList
     * @return
     */
    List<FilePO> listPO(List<String> idList);

    /**
     * 文件详情
     *
     * @param fileId
     * @return
     */
    FilePO getPO(String fileId);

    /**
     * 文件列表
     *
     * @param url 文件url
     * @return
     */
    List<FileDTO> listByUrl(String url);

}
