#include "Ring.h"

//default constructor
Ring::Ring():
	daysTillVaccinationEffective(1),
	probabilityVaccinationIneffective(0.001),
	amountVaccine(100){}


//default destructor
Ring::~Ring() {
	//do stuff
}

void Ring::DisplayMenu() {

	cout << endl << "\t Ring Vaccination Model parameters" << endl;
	cout << "Please enter the number of days it takes for the vaccination to be effective: ";
	cin >>  daysTillVaccinationEffective;
	cout << endl;
	while(daysTillVaccinationEffective < 0){
		cout << "Invaild Number of Days till vaccination effective." << endl;
		cout << "Number of days it takes for the vaccination to be effective: ";
		cin >>  daysTillVaccinationEffective;
		cout << endl;
	}
	cout << "Please enter the probability that the vaccine may be ineffective (0 to 1): ";
	cin >> probabilityVaccinationIneffective;
	cout << endl;
	while(probabilityVaccinationIneffective < 0 || probabilityVaccinationIneffective > 1){
		cout << "Invaild probability that the vaccine  is uneffective" << endl;
		cout << "Probability that the vaccine may be ineffective (0 to 1): ";
		cin >> probabilityVaccinationIneffective;
		cout << endl;
	}
	cout << "Please enter the original amount of vaccine at the start of the current simulation: ";
	cin >> amountVaccine;
	cout << endl;
	while(amountVaccine < 0){
		cout << "Invaild vaccine amount value." << endl;
		cout << "Original amount of vaccine at the start of the current simulation: ";
		cin >> amountVaccine;
		cout << endl;
	}
	cout << "Please enter the vaccination ring size: ";
	cin >> ringRadius;
	cout << endl;
	while(ringRadius < 0){
		cout << "Invaild ring size." << endl;
		cout << "Please enter the vaccination ring size: ";
		cin >> ringRadius;
		cout << endl;
	}

}

void Ring::Run(City * targetCity) {
	int numRows, numCols, ringLeftBound, ringRightBound, ringTopBound, ringBottomBound;

	//we don't really care about the probability the vaccination is uneffective,
	//but the infection/transmissions do care about the variable, which is static
	//for a given city, and thus makes sense to set it in the city object
	targetCity->SetVaccineIneffectiveness(probabilityVaccinationIneffective);
	targetCity->SetDaysUntilVaccineEffective(daysTillVaccinationEffective);

	numRows = targetCity->GetRows();
	numCols = targetCity->GetColumns();

	for (int r = 0; r<numCols; r++) {
		for (int c = 0; c<numRows; c++) {
			if(targetCity->IsContagious(r, c)) {
				//loop through the square ringRadius to the left, right, above
				//and below r,c and vaccinate, if possible (and within bounds)
				ringLeftBound = r - ringRadius;
				ringRightBound = r + ringRadius;
				ringTopBound = c - ringRadius;
				ringBottomBound = c + ringRadius;
				for(int rr = ringTopBound; rr <= ringBottomBound; rr++) {
					for(int cc = ringLeftBound; cc <= ringRightBound; cc++) {
						if(rr>=0 && rr < numRows) {
							if(cc>=0 && cc < numRows && amountVaccine > 0) {
								targetCity->VaccinateLocation(rr,cc);
								amountVaccine--;
							}
						}
					}
				}
			}
		}
	}
}
