/**
 * 数据(图片等)上传Minio服务器
 * */

#ifndef TOMINIOSRVENGINE_H
#define TOMINIOSRVENGINE_H

#include "AppCommon.h"
#include "EngineBase.h"
#include "EngineFactory.h"
#include "json/json.h"
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentialsProvider.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/CreateBucketRequest.h>
#include <aws/s3/model/DeleteBucketRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/DeleteObjectRequest.h>

using namespace ai_matrix;

class ToMinioSrvEngine : public ai_matrix::EngineBase
{
public:
    ToMinioSrvEngine();
    ~ToMinioSrvEngine();

    APP_ERROR Init() override;
    APP_ERROR DeInit() override;
    APP_ERROR Process() override;

private:
    bool CreateBucket(const std::string &strBucketName);
    bool DeleteBucket(const std::string &strBucketName);
    bool PutObject(std::string strBucketName, std::string strObjectKey, std::string strPathkey);
    bool DeleteObject(std::string strBucketName, std::string strObjectKey);
    //数据上传
    bool DataToMinioSrv(Json::Value &jvFtpData);
    //处理上传失败的信息
    void DealMinioFailInfo();
    //保存上传失败的信息
    bool SaveMinioFailInfo(Json::Value &jvFtpData, std::string &strFilePath);

    ai_matrix::MinioConfig minioConfig_;
    ai_matrix::BaseConfig baseConfig_;

    std::string strPort0_;
    std::string strFailSavePath_;       //失败信息保存文件
    std::string strFailSaveBakPath_;    //失败信息保存文件备份

    Aws::SDKOptions options_;
    Aws::S3::S3Client* client_;

};

ENGINE_REGIST(ToMinioSrvEngine)
#endif
