package app.model;

public class Model {

	public static boolean validID(String ID) {
		boolean valid = true;

		for (int i = 0; i < ID.length(); i++) {
			char c = ID.charAt(i);
			if (!validChar(c)) {
				valid = false;
				break;
			}
		}

		return valid;
	}

	public static boolean validChar(char c) {
		if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
				|| (c >= 'A' && c <= 'Z')) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean validDigit(char c) {
		if (c >= '0' && c <= '9') {
			return true;
		} else {
			return false;
		}
	}

	public static Integer currentHighestBid(String itemID) {
		if (itemID.length() > 2) {
			return itemID.substring(0, 2).hashCode();
		} else {
			return itemID.hashCode();
		}
	}

	public static boolean buyWithCard(String cardNum) {
		if (cardNum.length() != 16 || cardNum.charAt(0) == '0') {
			return false;
		} else {
			boolean valid = true;
			for (int i = 0; i < 16; i++) {
				char c = cardNum.charAt(i);
				if (!validDigit(c)) {
					valid = false;
					break;
				}
			}

			return valid;
		}
	}
}