package me.blackphreak.Grade;

import static me.blackphreak.Lib.promptQuestion;
import static me.blackphreak.Lib.tryParseUInt;

public class Grade {
	private String _grade;
	private int _sem;
	private boolean _inProgress;
	public boolean haveChanges = false;
	
	public Grade(String grade, int semester, boolean isInProgress) {
		this._grade = grade;
		this._sem = semester;
		this._inProgress = isInProgress;
	}
	
	public Grade() {
		do {
			var inp = promptQuestion("    That student still studying in this subject? [Y/N]");
			if (inp.equalsIgnoreCase("y"))
			{
				this._inProgress = true;
				break;
			}
			else if (inp.equalsIgnoreCase("n"))
			{
				this._inProgress = false;
				break;
			}
			else
				System.out.println("Invalid input. Try again.");
		} while (true);
		
		if (!this._inProgress)
		{
			do {
				var grade = promptQuestion("    What grade the student get in this subject? ");
				if (grade.matches("^[A-F]$"))
				{
					this._grade = grade;
					break;
				}
				
				System.out.println("Out of range. Must be within [A, B, C, D, E, F]");
			} while (true);
		}
		
		do {
			var inp = promptQuestion("    Which semester this student study this subject? ");
			var sem = tryParseUInt(inp, "Invalid number. [Parse Failed]");
			
			if (sem == -1)
				continue;
			
			if (sem < 0 || sem > 99)
			{
				System.out.println("Out of range. Must be within 1 - 99.");
				continue;
			}
			
			this._sem = sem;
			break;
		} while (true);
		
		this.haveChanges = true;
	}
	
	
	
	public String getGrade() {
		return _grade;
	}
	
	public void setGrade(String _grade) {
		if (this._grade.equals(_grade))
			return;
		
		this._grade = _grade;
		this.haveChanges = true;
	}
	
	public int getSem() {
		return _sem;
	}
	
	public void setSem(int _sem) {
		if (this._sem == _sem)
			return;
		
		this._sem = _sem;
		this.haveChanges = true;
	}
	
	public boolean isInProgress() {
		return _inProgress;
	}
	
	public void setInProgress(boolean _inProgress) {
		if (this._inProgress == _inProgress)
			return;
		
		this._inProgress = _inProgress;
		this.haveChanges = true;
	}
}
