package com.fdkankan.filestorage;



import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * 提供简化上传/下载的基本操作，复杂操作请使用原始客户端OSS.
 * <p>
 * 上传文件: uploadXxx 下载文件: downloadXxx
 */
@Service
public interface FileStorageTemplate {

    //------------------------------------------------------------------
    // 上传文件
    //------------------------------------------------------------------
    String uploadFile(String pathKey, String filePath);
    String uploadFile(String pathKey, String filePath, Map<String, String> headers);

    String uploadFile(String bucket, String pathKey, String filePath);
    String uploadFile(String bucket, String pathKey, String filePath, Map<String, String> headers);

    String uploadFileText(String pathKey, String text);

    String uploadFileText(String bucket, String pathKey, String text);

    String uploadFileBase64Image(String pathKey, String base64);

    String uploadFileBase64Image(String bucket, String pathKey, String base64);

    String uploadFileBytes(String pathKey, byte[] bytes);

    String uploadFileBytes(String bucket, String pathKey, byte[] bytes);

    String uploadFileStream(String pathKey, InputStream stream);

    String uploadFileStream(String bucket, String pathKey, InputStream stream);

    String uploadFileImage(String pathKey, String filePath);

    String uploadFileImage(String bucket, String pathKey, String filePath);

    //------------------------------------------------------------------
    // 下载文件
    //------------------------------------------------------------------

    File downloadFileTmp(String pathKey);

    File downloadFileTmp(String bucket, String pathKey);

    Object downloadFile(String pathKey, String file);

    Object downloadFile(String bucket, String pathKey, String file);

    Object downloadFile(String pathKey, Consumer<InputStream> handler);

    Object downloadFile(String bucket, String pathKey, Consumer<InputStream> handler);

    //------------------------------------------------------------------
    // 辅助方法
    //------------------------------------------------------------------

     boolean ossDownloadFileToLocal(String path,String localPath);
      boolean ossDownloadFileToLocal(String bucket,String path, String localPath);
    Boolean copyObject(String oldPath, String newPath);

    Boolean copyObject(String bucket, String oldPath, String toBucket, String newPath);
    void copyFolder(String sourcePath, String targetPath) ;
    void copyFolder(String sourceBucketName,String sourcePath, String targetBucketName, String targetPath) ;

    void deleteObject(String keyName);

    void deleteObject(String bucket, String keyName);

    /**
     * 获取文件夹
     *
     * @param keyName
     * @return
     */
    List<String> getFileFolder(String keyName);

    List<String> getFileFolder(String bucket, String keyName);

    boolean doesObjectExist(String bucket, String keyName);

    boolean doesObjectExist(String keyName);

    String getBucket();
    String getActive();
    String calculateUrl(String pathKey);
    String calculateUrl(String bucket, String pathKey);
    String getHostByBucket(String bucket);

    String getFileContent(String bucket, String keyName) throws Exception;

    String getFileContent(String keyName) throws Exception;

    Long getSpace(String bucket, String key);
    Long getSpace( String key);
    String getInternalEndpoint(String bucket ,String key);
    String getInternalEndpoint(String key);

    public URL getPresignedUrl(String bucket, String key);
    public URL getPresignedUrl( String key);

}
