package io.wdd.func.oss.service;

import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object;
import io.wdd.func.oss.config.OctopusObjectSummary;
import io.wdd.func.oss.config.OssConfig;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;
import java.util.List;

public interface OSSCoreService {

    /**
     * 对桶的操作
     *
     *
     */


    /**
     * 列出全部的桶对象
     */
    List<List<Bucket>> listAllBucket();

    /**
     * 列出所有的桶 Lists all buckets owned by the authenticated sender of the request.
     * <p>
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Bucket/GetService
     *
     * @return
     */
    List<Bucket> listBucketList(OssConfig ossConfig);


    /**
     * Lists up to 1000 objects in the specified bucket.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Bucket/ListObjects
     *
     * @param ossConfig
     * @param bucketName
     * @return
     */
    ObjectListing listBucketObjects(OssConfig ossConfig, String bucketName);

    /**
     * Checks to see if a bucket exists and that the requester has permission to access it.
     *
     * @param ossConfig
     * @param bucketName
     */
    void headBucket(OssConfig ossConfig, String bucketName);


    /**
     * Creates a new bucket.
     * <p>
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Bucket/PutBucket
     *
     * @param ossConfig
     * @param bucketName
     * @return
     */
    Bucket createBucket(OssConfig ossConfig, String bucketName);


    /**
     * Deletes a bucket. All objects in the bucket must be deleted before the bucket itself can be deleted.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Bucket/DeleteBucket
     *
     * @param ossConfig
     * @param bucketName
     * @return
     */
    boolean deleteBucket(OssConfig ossConfig, String bucketName);

    /**
     * Get the location of bucket's region.
     * <p>
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Bucket/GetLocation
     *
     * @param ossConfig
     * @param bucketName
     */
    void getBucketLocation(OssConfig ossConfig, String bucketName);



    /* *
     * 对象操作
     * */


    /**
     * Retrieves an object.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/GetObject
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    OctopusObjectSummary getObjectSimple(OssConfig ossConfig, String bucketName, String objectName);


    /**
     * Retrieves an object.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/GetObject
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    S3Object getObject(OssConfig ossConfig, String bucketName, String objectName);

    /**
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/DeleteObject
     * Deletes an object.
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    boolean deleteObject(OssConfig ossConfig, String bucketName, String objectName);

    /**
     * Gets the user-defined metadata and entity tag for an object.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/HeadObject
     *
     * @param ossConfig
     * @param objectName
     * @return
     */
    ObjectMetadata headObject(OssConfig ossConfig, String bucketName, String objectName);


    /**
     * Creates a new object or overwrites an existing one.
     * <p>
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/PutObject
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    HashMap<String, String> createObject(OssConfig ossConfig, String bucketName, String objectName, MultipartFile file);


    /**
     * 根据ossConfig查询得到一个随机公开的桶，然后上传
     *
     * @param ossConfig
     * @param objectName
     * @param file
     * @return
     */
    OctopusObjectSummary createObject(OssConfig ossConfig, String objectName, File file);

    /**
     * Creates a new object or overwrites an existing one.
     * <p>
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/PutObject
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    OctopusObjectSummary createObject(OssConfig ossConfig, String bucketName, String objectName, File file);


    /**
     * Restores the object as defined in the request body.
     * https://docs.oracle.com/en-us/iaas/api/#/en/s3objectstorage/20160918/Object/RestoreObjects
     *
     * @param ossConfig
     * @param bucketName
     * @param objectName
     * @return
     */
    String restoreObject(OssConfig ossConfig, String bucketName, String objectName);


}
