package oving2;

public class Vehicle {
	private char vehicleType;
	private char fuelType;
	private String registrationNumber;

	Vehicle(char vehicleType, char fuelType, String regstrationNumber) {
		setVehicleType(vehicleType);
		setFuelType(fuelType);
		setRegistrationNumber(registrationNumber);
	}

	char getVehicleType() {
		return vehicleType;
	}

	char getFuelType() {
		return fuelType;
	}

	String getRegistrationNumber() {
		return registrationNumber;
	}

	void setVehicleType(char vehicleType) {
		if (vehicleType != 'M' && vehicleType != 'C') {
			throw new IllegalArgumentException("Invalid vehicle type, found: \"" + vehicleType + "\"");
		}
		this.vehicleType = vehicleType;
	}

	void setFuelType(char fuelType) {
		if (fuelType != 'H' && fuelType != 'E' && fuelType != 'D' && fuelType != 'G') {
			throw new IllegalArgumentException("Invalid vehicle type, found: \"" + fuelType + "\"");
		}
		this.fuelType = vehicleType;
	}

	void setRegistrationNumber(String registrationNumber) {
		String code = registrationNumber.substring(0, 2);
		if (fuelType == 'E' && code != "EL" && code != "EK") {
			throw new IllegalArgumentException(
					"Electric vehicles should have registraition number starting with EL or EK, got: "
							+ registrationNumber + "\"");
		} else if (fuelType == 'H' && code != "HY") {
			throw new IllegalArgumentException(
					"Hydrogen vehicles should have registraition number starting with HY, got: " + registrationNumber
							+ "\"");
		} else if ((fuelType == 'D' || fuelType == 'G') && (code == "EL" || code == "EK" || code == "HY")) {
			throw new IllegalArgumentException(
					"Diesel or gas vehicles should have reigstartion number not starting with EL, EK, or HY.");

		} 
		if (vehicleType == 'C' && registrationNumber.length() != 7) {
			throw new IllegalArgumentException(
					"Cars have a registrationNumber of length 7" + registrationNumber + "\"");
		}
		if (vehicleType == 'M' && registrationNumber.length() != 6) {
			throw new IllegalArgumentException(
					"Motorbikes have a registrationNumber of length 6" + registrationNumber + "\"");
		}
		this.registrationNumber = registrationNumber;
	}
}
