package edu.uchicago.cs.java.finalproject.tronscan;

public  class Answer {
	
	private int[] nChadVals ;
	private int nDarkest;
	private boolean bActive;
	private boolean bMaster;
	
	
	public Answer(int[] nChads, boolean bMaster) {

		this.nChadVals = nChads;
		determineActivity();
		determineDarkest();
		this.bMaster = bMaster;
		
	

	}
	

	public boolean isMaster() {
		return this.bMaster;
	}



	public void setMaster(boolean bMaster) {
		this.bMaster = bMaster;
	}



	public boolean isActive() {
		if(bMaster)
		     return this.bActive;
		else{
			return false;
		}
	}


	public void setActive(boolean bActive) {
		this.bActive = bActive;
	}


	public int[] getChads() {
		return this.nChadVals;
	}
	public void setChads(int[] nChads) {
		this.nChadVals = nChads;
	}

	//this is your answer
	public int getDarkest() {
		return this.nDarkest;
	}


	public void setDarkest(int nDarkest) {
		this.nDarkest = nDarkest;
	}

	
	
	private void determineDarkest(){
		
		if(!bActive){
			this.nDarkest = -99;
			return;
		}
		
		int nValLow = nChadVals[0];
		int nDarky = 0;
		for (int nC = 1; nC < nChadVals.length; nC++) {
			if(nChadVals[nC] < nValLow){
				nDarky = nC;
			   nValLow = nChadVals[nC];
			}
		}
		
		this.nDarkest = nDarky;
		
	}
	
	
	
	private void determineActivity(){

		boolean bActive = false; //assume the answer is not active (not filled out by the teacher)
		for (int nC = 0; nC < nChadVals.length; nC++) {
			

			if(nChadVals[nC] < 210){
				bActive = true;
			     break;
			}
		}
		
		this.bActive = bActive;
		
	}
	
	
	@Override
	public String toString(){
		String strTemp = " answer> ";
		for (int nC = 0; nC < nChadVals.length; nC++) {
			strTemp += nChadVals[nC] + " : "; 
		}
		strTemp += " " + getLetter(getDarkest()) + " ";
		
		if(bMaster)
		     strTemp += isActive();
		
		return strTemp;
		
	}
	
	private String getLetter(int nN){

		String strRet = "";
		switch (nN) {
		case 0:
			strRet ="A";
			break;
		case 1:
			strRet = "B";
			break;
		case 2:
			strRet = "C";
			break;
		case 3:
			strRet = "D";
			break;
		case 4:
			strRet = "E";
			break;
		case -99:
			strRet = "NOT ANSWERED";
			break;
		default:
			strRet =  "";
			break;
		
		}
		return strRet;
		
	}//end getLetter
	

}
