#ifndef compressedh
#define compressedh
#include <string>
#include <fstream>
#include "miniplayer.h"
using namespace std;

struct compressed
{
	unsigned short int playerid, id, exscore, just, great, good, bad, poor;
	char diff, grade, djpoints, highspeed, hidsud, hardeasy,ranmir, autoscratch,
		cleartype, comment, picurl;
	unsigned int date;
};

string assigndata(player*& p1, const int& index)
{
	compressed data;
	data.playerid=valueof(p1->id.getbody());
	data.id=valueof(p1->scores[index].id.getbody());
	data.exscore=valueof(p1->scores[index].exscore.getbody());
	data.just=valueof(p1->scores[index].justgreats.getbody());
	data.great=valueof(p1->scores[index].greats.getbody());
	data.good=valueof(p1->scores[index].good.getbody());
	data.bad=valueof(p1->scores[index].bad.getbody());
	data.poor=valueof(p1->scores[index].poor.getbody());
	
	if(p1->scores[index].diff=="5")	data.diff='7';
	else if(p1->scores[index].diff=="L7")	data.diff='1';
	else if(p1->scores[index].diff=="7")	data.diff='2';
	else if(p1->scores[index].diff=="A")	data.diff='3';
	else if(p1->scores[index].diff=="L14")	data.diff='4';
	else if(p1->scores[index].diff=="14")	data.diff='5';
	else if(p1->scores[index].diff=="A14")	data.diff='6';

	if(p1->scores[index].grade.getbody()=="AAA") data.grade='Z';
	else if(p1->scores[index].grade.getbody()=="AA") data.grade='Y';
	else data.grade=p1->scores[index].grade.getbody()[0];

	data.djpoints=valueof(p1->scores[index].djpoints.getbody());

	if(p1->scores[index].highspeed.getbody()=="-2")	data.highspeed='A';
	else if(p1->scores[index].highspeed.getbody()=="-1")	data.highspeed='B';
	else if(p1->scores[index].highspeed.getbody()=="0")	data.highspeed='C';
	else if(p1->scores[index].highspeed.getbody()=="0.5")	data.highspeed='D';
	else if(p1->scores[index].highspeed.getbody()=="1")	data.highspeed='E';
	else if(p1->scores[index].highspeed.getbody()=="1.5")	data.highspeed='F';
	else if(p1->scores[index].highspeed.getbody()=="2")	data.highspeed='G';
	else if(p1->scores[index].highspeed.getbody()=="2.5")	data.highspeed='H';
	else if(p1->scores[index].highspeed.getbody()=="3")	data.highspeed='I';
	else if(p1->scores[index].highspeed.getbody()=="3.5")	data.highspeed='J';
	else if(p1->scores[index].highspeed.getbody()=="4")	data.highspeed='K';
	else if(p1->scores[index].highspeed.getbody()=="4.5")	data.highspeed='L';
	else if(p1->scores[index].highspeed.getbody()=="5")	data.highspeed='M';
	else data.highspeed='X';

	if(p1->scores[index].hidsud.getbody()=="")	data.hidsud='0';
	else if(p1->scores[index].hidsud.getbody()=="H")	data.hidsud='H';
	else if(p1->scores[index].hidsud.getbody()=="S")	data.hidsud='S';
	else if(p1->scores[index].hidsud.getbody()=="B")	data.hidsud='B';
	else if(p1->scores[index].hidsud.getbody()=="T")	data.hidsud='T';
	else if(p1->scores[index].hidsud.getbody()=="H+")	data.hidsud='Y';
	else if(p1->scores[index].hidsud.getbody()=="S+")	data.hidsud='Z';
	else data.hidsud='X';

	if(p1->scores[index].hardeasy.getbody()=="")	data.hardeasy='0';
	else if(p1->scores[index].hardeasy.getbody()=="H")	data.hardeasy='H';
	else if(p1->scores[index].hardeasy.getbody()=="E")	data.hardeasy='E';
	else data.hardeasy='X';

	if(p1->scores[index].ranmir.getbody()=="")	data.ranmir='0';
	else if(p1->scores[index].ranmir.getbody()=="R")	data.ranmir='R';
	else if(p1->scores[index].ranmir.getbody()=="M")	data.ranmir='M';
	else if(p1->scores[index].ranmir.getbody()=="B")	data.ranmir='B';
	else data.ranmir='X';

	if(p1->scores[index].autoscratch.getbody()=="")	data.autoscratch='0';
	else data.autoscratch='A';

	if(p1->scores[index].cleartype.getbody()=="played")		data.cleartype='A';
	else if(p1->scores[index].cleartype.getbody()=="cleared")	data.cleartype='B';
	else if(p1->scores[index].cleartype.getbody()=="combo")		data.cleartype='C';
	else if(p1->scores[index].cleartype.getbody()=="perfect")	data.cleartype='D';
	else if(p1->scores[index].cleartype.getbody()=="comboed")	data.cleartype='E';
	else if(p1->scores[index].cleartype.getbody()=="perfected")	data.cleartype='F';
	else data.cleartype='X';

	if(p1->scores[index].comment.getbody()=="")	data.comment='N';
	else data.comment='Y';

	if(p1->scores[index].picurl.getbody()=="")	data.picurl='N';
	else data.picurl='Y';

	string str=p1->scores[index].date.getbody();
	int year =valueof(str.substr(0,4));
	int month=valueof(str.substr(5,2));
	int day  =valueof(str.substr(8,2));
	int hour =valueof(str.substr(11,2))+4; //EDT -> UTC
	int min  =valueof(str.substr(14,2));
	int sec  =valueof(str.substr(17,2));
	data.date=(unsigned int)(hrconvert(year,month,day,hour,min,sec)*3600);

	string ret="";
	ret+=char(data.playerid/256);	//0
	ret+=char(data.playerid%256);
	ret+=data.diff;
	ret+=char(data.id/256);
	ret+=char(data.id%256);
	ret+=char(data.exscore/256);	//5
	ret+=char(data.exscore%256);
	ret+=data.grade;
	ret+=data.djpoints;
	ret+=char(data.just/256);	//9
	ret+=char(data.just%256);
	ret+=char(data.great/256);
	ret+=char(data.great%256);
	ret+=char(data.good/256);
	ret+=char(data.good%256);
	ret+=char(data.bad/256);
	ret+=char(data.bad%256);
	ret+=char(data.poor/256);
	ret+=char(data.poor%256);
	ret+=data.highspeed;		//19
	ret+=data.hidsud;
	ret+=data.hardeasy;
	ret+=data.ranmir;
	ret+=data.autoscratch;
	ret+=data.cleartype;
	ret+=data.comment;
	ret+=data.picurl;
	ret+=char(data.date/(256*256*256));	//27
	ret+=char(data.date/(256*256)%256);
	ret+=char(data.date/(256)%256);
	ret+=char(data.date%256);

	return ret;
};

#endif
