package controller.console.administrateur;

import java.util.InputMismatchException;
import java.util.Scanner;

import controller.Database;

import view.console.administrateur.Menu;

public class MenuControle {
	private Scanner sc;
	private int input;
	
	public MenuControle(Database d) {
		boolean done = false;
		sc = new Scanner(System.in);
		
		Menu.trigger();
		while (!done) {
			try {
				Menu.askInput();
				this.askInput();
				if (this.input == 0) {
					done = true;
				} else if (this.input == 1) {
					Utilisateur_GestionControle ugc = new Utilisateur_GestionControle(d);
					ugc.updateDatabase(d);
				} else if (this.input == 2) {
					Module_GestionControle mgc = new Module_GestionControle(d);
					mgc.updateDatabase(d);
				} else {
					Promo_GestionControle pgc = new Promo_GestionControle(d);
					pgc.updateDatabase(d);
				}
			} catch (InputMismatchException e) {
				sc.nextLine();
				Menu.fail();
			}
		}
		
	}
	
	private void askInput() throws InputMismatchException {
		input = sc.nextInt();
		sc.nextLine();
		if ((input < 0) || (input > 3)) {
			throw new InputMismatchException();
		}
	}
	
	public void close() {
		Menu.close();
	}
}
