package com.dji.sample.media.service;

import com.dji.sample.map.model.param.MediaFileQueryParam;
import com.dji.sample.media.model.MediaFileDTO;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.media.model.UploadResultDTO;
import com.dji.sample.media.model.UpstreamMediaFileDTO;
import com.dji.sdk.cloudapi.map.ElementPicture;
import com.dji.sdk.cloudapi.media.MediaUploadCallbackRequest;
import com.dji.sdk.common.PaginationData;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * @author sean
 * @version 0.2
 * @date 2021/12/9
 */
public interface IFileService {

    MediaFileDTO getMediaFileByFileId(String workspaceId, String fileId);

    ElementPicture getMediaFileByElementId(String workspaceId, String elementId);

    List<ElementPicture> getElementMediaFiles(String workspaceId);

    /**
     * Query if the file already exists based on the workspace id and the fingerprint of the file.
     * @param workspaceId
     * @param fingerprint
     * @return
     */
    Boolean checkExist(String workspaceId, String fingerprint);

    void uploadMediaFile(MultipartFile file, String workspaceId, String dirId, String creator);

    /**
     * Save the basic information of the file to the database.
     * @param workspaceId
     * @param file
     * @return
     */
    Integer saveFile(String workspaceId, MediaUploadCallbackRequest file);

    /**
     * Query information about all files in this workspace based on the workspace id.
     * @param workspaceId
     * @return
     */
    List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId);

    /**
     * Paginate through all media files in this workspace.
     * @param workspaceId
     * @param page
     * @param pageSize
     * @return
     */
    PaginationData<MediaFileDTO> getMediaFilesPaginationByWorkspaceId(String workspaceId, MediaFileQueryParam mediaFileQueryParam, long page, long pageSize);

    /**
     * Get the download address of the file.
     * @param workspaceId
     * @param fileId
     * @return
     */
    URL getObjectUrl(String workspaceId, String fileId);

    /**
     * Query all media files of a job.
     * @param workspaceId
     * @param jobId
     * @return
     */
    List<MediaFileDTO> getFilesByWorkspaceAndJobId(String workspaceId, String jobId);

    /**
     * 通过文件夹ID获取文件
     * @param dirId
     * @param page
     * @param pageSize
     * @param param
     * @return
     */
    PaginationData<MediaFileDTO> getMediaFilesPaginationByDirId(String dirId, long page, long pageSize,MediaFileQueryParam param);

    List<MediaFileDTO> getMediaFilesByDirId(String dirId);

    List<MediaFileEntity> getFlightTrackMediaFiles(String workspaceId, String droneSn, long startTime, long endTime);

    void deleteFiles(List<String> fileIds);

    void dowloadDirsToZip(String workspaceId, List<String> dirIds, HttpServletResponse response) throws Exception;

    void dowloadFilesToZip(String workspaceId, List<String> fileIds, HttpServletResponse response) throws Exception;

    Map<Integer,Long> getParentDirSize(List<Integer> dirIds);

    Boolean updateFile(MediaFileDTO mediaFileDTO);

    Boolean updateElementId(MediaFileDTO mediaFileDTO);

    boolean createMediaElement(String workspaceId, Integer elementFrom, MediaFileDTO mediaFileDTO);

    boolean deleteMediaElement(String workspaceId, MediaFileDTO mediaFileDTO);

    PaginationData<UpstreamMediaFileDTO> getMediaFilesPagination(String workspaceName, Long startTime, Long endTime, long page, long pageSize,String workspaceId);

    UploadResultDTO uploadFile(MultipartFile file,String creator);

    void deleteByDirId(String dirId);

    void deleteFileById(String id);

    public void importZipFile(MultipartFile file, String workspaceId, String creator);
}
