#include <iostream>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include "FtpHelper.h"


void test1()
{
	FtpHelper ftpHelper("ftp://test:test@sanjeevs", false);
	FtpHelper::FileList fileList;
	
	FtpHelper::StatusCodeHelper code = ftpHelper.GetFileList(fileList);
	if (FtpHelper::STATUS_CODE_ERROR == code)
		std::cout<< code.ToString();
	
	for (FtpHelper::FileList::iterator it = fileList.begin(), itEnd = fileList.end(); it != itEnd; ++it)
	{
		ftpHelper.GetFile(*it);
		ftpHelper.DeleteFile(*it);
	}
};

void test2()
{
	FtpHelper ftpHelper("ftp://test:test@sanjeevs", false);
	FtpHelper::FileList fileList;
	
	FtpHelper::StatusCodeHelper code = ftpHelper.GetFileList(fileList);
	if (FtpHelper::STATUS_CODE_ERROR == code)
	{
		std::cout<< code.ToString();
		return;
	}
	time_t totalDownloadTime = 0;
	time_t totalDeleteTime = 0;
	{
		for (FtpHelper::FileList::iterator it = fileList.begin(), itEnd = fileList.end(); it != itEnd; ++it)
		{
			time_t start = time(NULL);
			ftpHelper.GetFile(*it);
			totalDownloadTime += time(NULL) - start;

			//ftpHelper.DeleteFile(*it);
		}
	}

	{
		for (FtpHelper::FileList::iterator it = fileList.begin(), itEnd = fileList.end(); it != itEnd; ++it)
		{
			//ftpHelper.GetFile(*it);
			time_t start = time(NULL);
			ftpHelper.DeleteFile(*it);
			totalDeleteTime += time(NULL) - start;
		}
	}

	std::cout << "Total number fo files downloaded " << fileList.size() << std::endl;
	std::cout << "Total download time " << totalDownloadTime << std::endl;
	std::cout << "Total delete time " << totalDeleteTime << std::endl;
	std::cout << "Average download time " << (double)totalDownloadTime / fileList.size() << std::endl;
	std::cout << "Average delete time " << (double)totalDeleteTime  / fileList.size() << std::endl;
};


int main(void)
{
	
	test2();
	return 0;
}

