#include "SnapFile.h"

using namespace std;

#define IDX "DataCenter/idx.txt"

void testList();
void testCompare();
void testChoose();
void testAdd();
void testKeypad();

int main(int argc, char const *argv[])
{
	cout << "Bienvenue dans le test de SnapFile." << endl;

	if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
    {
        std::cout << "Impossible to init SDL: " << SDL_GetError() << std::endl;
        return 1;
    }
    atexit(SDL_Quit);

	//testList();
	//testCompare();
	testChoose();
	//testAdd();
	//testKeypad();

	return 0;
}

void testList()
{
	// Data
	vector<string> file_list;

	string index( IDX );

	// Test SF_makeList
	SF_makeList( index, file_list );

	cout << "Voici les petits fichiers indexés :" << endl;

	for( auto iter( file_list.begin() ); iter != file_list.end(); iter ++ )
	{
		cout << "> " << *iter << endl;
	}

	// Test SF_filter
	SF_filter( file_list, "spc", true);

	cout << endl << "On garde les spc seulement :" << endl;

	for( auto iter( file_list.begin() ); iter != file_list.end(); iter ++ )
	{
		cout << "> " << *iter << endl;
	}
}

void testCompare()
{
	// Test comparaison
	string motif;
	string ref;
	unsigned int pos, len;

	cout << endl << "Rentrez un mot : ";
	cin >> ref;

	cout << endl << "Rentrez le motif : ";
	cin >> motif;

	cout << endl << "Rentrez la position : ";
	cin >> pos;

	cout << endl << "Rentrez la longueur : ";
	cin >> len;

	cout << endl << "Comparaison : " << ref.compare( pos, len, motif ) << endl;
}

void testChoose()
{
	// Test charge
	string index( IDX );
	string fileChosen("");
	SF_choose( index, fileChosen );

	if ( fileChosen == "" )
		cout << endl << "Pas de fichier sélectionné." << endl;
	else
		cout << endl << "Vous avez sélectionné le fichier : " << fileChosen << endl;
}

void testAdd()
{
	// Data
	string index( IDX );

	// Voir
	cout << endl << "Regarder les fichiers indexés !" << endl;
	testList();

	string chaine("Sans Nom");
	// Ajouter en C++
	/*cout << endl << "Inscrivez une nouvelle entrée pour l'index :" << endl << ">>>";
	cin >> chaine;

	SF_addFile( index, chaine );*/

	// Ajouter en SDL
	cout << endl << "Une petite fenere SDL, une !" << endl;
	SF_addAskedFile( index, chaine );
	cout << "Le fichier saisi s'appelle " << chaine << endl;


	// Revoir
	cout << endl << "Vérifiez les fichiers indexés !" << endl;
	testList();
}

void testKeypad()
{
	// Test taper texte
	string name("Sans Nom");
	SF_keyName( name );
	if ( name == "" )
		cout << endl << "Pas de nom tapé." << endl;
	else
		cout << endl << "Nouveau nom : " << name << endl;
}