package xyz.thastertyn.Types;

/**
 * Stores the final mark from a subject
 */
public class FinalMark{
	public static final FinalMark VYBORNY = new FinalMark(1, "1");
	public static final FinalMark CHVALITEBNY = new FinalMark(2, "2");
	public static final FinalMark DOBRY = new FinalMark(3, "3");
	public static final FinalMark DOSTATECNY = new FinalMark(4, "4");
	public static final FinalMark NEDOSTATECNY = new FinalMark(5, "5");

	public static final FinalMark NOTHING = new FinalMark(0, "");

	public static final FinalMark NEHODNOCEN = new FinalMark(-1, "N");
	public static final FinalMark NAPOMENUT_ZA_NEKLASIFIKACI = new FinalMark(-2, "N?");

	public static final FinalMark UVOLNEN = new FinalMark(-3, "U");

	public static final FinalMark NAPOMENUT_ZA_ZAOSTAVANI = new FinalMark(-4, "5?");

	public static final FinalMark UNKNOWN = new FinalMark(-5, "?");
	// #94701b
	private double value;
	private String stringValue;

	private FinalMark(double value, String stringValue)
	{
		this.stringValue = stringValue;
		this.value = value;
	}

	public FinalMark(double value)
	{
		this.value = value;
		this.stringValue = String.format("%.2f", value);
	}

	public double getValue()
	{
		return value;
	}

	@Override
	public String toString()
	{
		return stringValue;
	}
	
	public static FinalMark fromValue(String value)
	{
		if(!value.matches("[0-9]"))
		{
			return switch (value) {
				case "N" -> NEHODNOCEN;
				case "N?" -> NAPOMENUT_ZA_NEKLASIFIKACI;
				case "5?" -> NAPOMENUT_ZA_ZAOSTAVANI;
				case "U" -> UVOLNEN;
				default -> UNKNOWN;
			};
		}else{
			int numericValue = Integer.parseInt(value);

			return switch (numericValue) {
				case 1 -> VYBORNY;
				case 2 -> CHVALITEBNY;
				case 3 -> DOBRY;
				case 4 -> DOSTATECNY;
				case 5 -> NEDOSTATECNY;
				default -> UNKNOWN;
			};
		}
	}
}

