#ifndef _H_UFILESDK_C_UCLOUD_API_
#define _H_UFILESDK_C_UCLOUD_API_

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif
//*******************************common data********************************
struct __declspec(dllexport) ufile_error{
    const char * errorCode;
	const char * errorMessage;
	const char * resourceAddr;
	const char * cosRequestId;
	const char * cosTraceId;
	bool bIsSuccess;
	int httpStatus;
};

#define UFILE_OK  0
#define UFILE_ERROR_CODE -1
#define UFILE_CONFIG_ERROR_CODE -2
#define UFILE_MULTIPLE_INIT_ERROR_CODE -3
#define UFILE_PARAM_ERROR_CODE -4
#define UFILE_MULTIPLE_NOT_FINISH_ERROR_CODE -5
#define UFILE_BUCKET_REQ_ERROR_CODE -10
#define CURL_ERROR_CODE -20

#define NO_ERROR {0, ""} 
#define CURL_INIT_ERROR_MSG "init curl failed."

#define UFILE_HAS_ERROR(CODE) ((CODE) != 0 && (CODE)/100 != 2 )
//****************************************************************** end

//*********************************config
struct __declspec(dllexport) ufile_config{
    const char *public_key;   //json: public_key
    const char *private_key;  //json: private_key

    const char *file_host;    //json: file_host
    const char *bucket_host;  //json: bucket_host
	long long   appid;
	const char *region;
};

__declspec(dllexport) struct ufile_error
ufile_load_config_from_json(const char* json_buf, struct ufile_config *cfg);


__declspec(dllexport) void
ufile_free_config(struct ufile_config cfg);
//*********************************end config


__declspec(dllexport) struct ufile_error
ufile_sdk_initialize(const struct ufile_config cfg, int open_verbose);


__declspec(dllexport) void
ufile_sdk_cleanup();

//********************************************** file info

struct __declspec(dllexport) ufile_file_info{
    long long bytes_len;
    const char *etag;
    const char *mime_type;
};


__declspec(dllexport) struct ufile_error
ufile_head(const char* bucket_name, const char *key, struct ufile_file_info *info);


__declspec(dllexport) void
ufile_free_file_info(struct ufile_file_info info);
//***************************************************

__declspec(dllexport) struct ufile_error
ufile_put_buf(const char* bucket_name, const char *key, const char *mime_type, char *buffer, size_t buf_len);

__declspec(dllexport) struct ufile_error
ufile_put_file(const char* bucket_name, const char *key, const char *mime_type, FILE *file);

__declspec(dllexport) struct ufile_error
ufile_put_file_by_filepath(const char* bucket_name, const char *key, const char *mime_type, const char*file_path);

enum{
	company_ucloud, // ucloud 
	company_tx, //جعر¶
};
__declspec(dllexport) void
set_upload_company(int company);

__declspec(dllexport) struct ufile_error
ufile_delete(const char* bucket_name, const char *key);


__declspec(dllexport) struct ufile_mutipart_state{

    const char *bucket_name;

    const char *key;

    size_t part_size;
    const char *upload_id;
    struct etag_slist *etags;
    struct curls_list *curls;
};

__declspec(dllexport) struct ufile_error
ufile_multiple_upload_init(struct ufile_mutipart_state *self, const char *bucket_name, const char *key, const char* mime_type);


__declspec(dllexport) struct ufile_error
ufile_multiple_upload_part(struct ufile_mutipart_state *self, char *buffer, size_t buf_len, int part_number);


__declspec(dllexport) struct ufile_error
ufile_multiple_upload_finish(struct ufile_mutipart_state *self);


__declspec(dllexport) struct ufile_error
ufile_multiple_upload_abort(struct ufile_mutipart_state *self);


__declspec(dllexport) struct ufile_error
ufile_download(const char *bucket_name, const char *key, FILE *file, size_t *return_size,const char*path=0);


__declspec(dllexport) struct ufile_error
ufile_download_piece(const char *bucket_name, const char *key, size_t start_position, char *buf, size_t buf_len, size_t *return_size);


__declspec(dllexport) struct ufile_error
ufile_bucket_create(const char *bucket_name, const char* region, const char* bucket_type);


__declspec(dllexport) struct ufile_error
ufile_bucket_delete(const char *bucket_name);
#ifdef __cplusplus
}
#endif

#endif //_H_UFILESDK_C_UCLOUD_API_
