#include "Pokemon.h"
#include <vector>
#include <algorithm>


using namespace std;
Pokemon::Pokemon() {}

Pokemon::Pokemon(const std::string & n, const std::string & e): nom {n}, espece {e} {};

Pokemon::Pokemon(const std::string & n, const std::string & e, int p): nom {n}, espece {e}, pointCombat {p} {};

Pokemon::~Pokemon() {};

const std::string & Pokemon::getNom() const {
	return nom;
}

std::ostream & operator<<(std::ostream & out, const Pokemon & p){
	out << p.nom;
	out << " ";
	out << p.espece;
	out << " ";
	out << p.pointCombat;
	out << "\n";
	out << std::endl;
}

std::istream & operator>>(std::istream & in, Pokemon & p){
	if (!(in >> p.nom >> p.espece >> p.pointCombat)){
		in.setstate(std::ios::failbit);
	}
	return in;
}

bool Pokemon::operator<(const Pokemon & autre)const{
	return pointCombat<autre.pointCombat;
}


int main() {
	std::vector<Pokemon> v;
	Pokemon test ("bob", "chapeau", 15);
/*
	std::cout << test;
	std::cin >> test;
	std::cout << test;
*/
	ifstream ifs("Pokemons.txt");
	if(ifs){
		Pokemon p;
		while(!ifs.eof()){
			ifs>>p;
			if(!ifs.fail()){
				std::cout << p;
				v.push_back(p);
			}
		}
		ifs.close();
	}

bool b =true;
	for (std::vector<Pokemon>::iterator it = v.begin(); it != v.end(); ++it) {
		if(it->getNom()=="Pikachu"){
			std::cout << "Oui Pikachu fait parti du fichier\n" << std::endl;
			b=false;
		}
	}

	if(b){
		std::cout<< "pickachu n'est pas la"<< std::endl;
	}



	sort (v.begin(), v.end() );

	ofstream ofs("PokemonsTries.txt", ios::out);

	for (std::vector<Pokemon>::iterator it = v.begin(); it != v.end(); ++it) {
		ofs<<*it;
	}
	ofs.close();

	std::cout << "test" << std::endl;

	return 0;
}
