package me.blackphreak.Student;

import me.blackphreak.Debug.Debug;

import java.util.HashMap;

public abstract class AbstractStudent {
	
	private String _studentID;
	private String _chtName;  // chinese-traditional
	private String _engName;  // english
	private String _homeAddress;
	private String _mobileNumber;
	private HashMap</*subject*/String, /*grade*/String> _grades = new HashMap<>();
	private int    _semester;  // current semester
	private String _nationality;
	
	public void assign(String stuID,
	                       String chtName,
	                       String engName,
	                       String homeAddress,
	                       String mobileNumber,
	                       String nationality)
	{
		this._studentID = stuID;
		this._chtName = chtName;
		this._engName = engName;
		this._homeAddress = homeAddress;
		this._mobileNumber = mobileNumber;
		this._nationality = nationality;
	}
	
	public void printInfo() {
		System.out.println(String.format("Student ID [%s]", getStudentID()));
		System.out.println(String.format("    %13s: %s", "Chinese Name", getChtName()));
		System.out.println(String.format("    %13s: %s", "English Name", getEngName()));
		System.out.println(String.format("    %13s: %s", "Home Address", getHomeAddress()));
		System.out.println(String.format("    %13s: %s", "Mobile Number", getMobileNumber()));
		System.out.println(String.format("    %13s: %s", "Nationality", getNationality()));
		System.out.println(String.format("    %13s: %d", "Semester", getSemester()));
		
		printInfoExtra();
	}
	
	/**
	 * allocate a student ID from database and assign to the student directly
	 * @return assign success / fail
	 */
	public boolean allocateStudentID() {
		// TODO: get last studentID and then +1
		String id = "";
		return updateStudentID(id);
	}
	
	/**
	 * update the studentID and check for duplicate
	 * @param newStudentID a new studentID that want to assign with
	 * @return false when duplicated
	 */
	public boolean updateStudentID(String newStudentID) {
		// TODO: check for duplicate
		if (true) {
			// if duplicated
			Debug.err("Failed to update studentID ["+getStudentID()+"] to ["+newStudentID+"]");
			return false;
		}
		
		// no duplicate
		if (true) {
			this._studentID = newStudentID;
		}
		return true;
	}
	
	public abstract void printInfoExtra();
	
	// --- getter/setter ---
	public String getStudentID() {
		return _studentID;
	}
	
	public String getChtName() {
		return _chtName;
	}
	
	public void setChtName(String _chtName) {
		this._chtName = _chtName;
	}
	
	public String getEngName() {
		return _engName;
	}
	
	public void setEngName(String _engName) {
		this._engName = _engName;
	}
	
	public String getHomeAddress() {
		return _homeAddress;
	}
	
	public void setHomeAddress(String _homeAddress) {
		this._homeAddress = _homeAddress;
	}
	
	public String getMobileNumber() {
		return _mobileNumber;
	}
	
	public void setMobileNumber(String _mobileNumber) {
		this._mobileNumber = _mobileNumber;
	}
	
	public HashMap<String, String> getGrades() {
		return _grades;
	}
	
	public void setGrades(HashMap<String, String> _grades) {
		this._grades = _grades;
	}
	
	public int getSemester() {
		return _semester;
	}
	
	public void setSemester(int _semester) {
		this._semester = _semester;
	}
	
	public String getNationality() {
		return _nationality;
	}
	
	public void setNationality(String nationality) {
		this._nationality = nationality;
	}
	
}