package controller;

import java.util.Vector;

import model.gammeOperatoire.GammeOperatoire;

public class GestionCommande {

	//////////Attribut //////////

	// Liste statique des gammes operatoires
	public static Vector<GammeOperatoire> commande;

	// Constructeur pour l'initialisation de la commande
	public GestionCommande() {
		commande = new Vector<GammeOperatoire>();
	}

	//////////Methodes //////////

	// Recherche et renvoi d'une gamme dans la commande a partir de sa reference
	public static GammeOperatoire getGamme(String reference){
		for (int i=0;i<commande.size();i++){
			if (reference.equals(commande.get(i).getReference())) return commande.get(i);
		}
		return null;
	}

	// Ajoute une gamme dans la commande a partir d'une gamme existante
	public static void ajouterGamme(GammeOperatoire gamme){
		commande.add(gamme);
	}

	// Ajoute une gamme dans la commande a partir de la position de celle-ci dans la liste des gammes
	public static boolean ajouterGamme(int pos){
		if (pos<GestionGamme.listeGammes.size()) {
			commande.add(GestionGamme.listeGammes.get(pos));
			return true;
		}
		return false;
	}

	// Ajoute une gamme dans la commande a partir de la reference de celle-ci
	public static boolean ajouterGamme(String reference){
		for(int i=0;i<GestionGamme.listeGammes.size();i++){
			if (reference.equals((String) GestionGamme.listeGammes.get(i).getReference())){
				commande.add(GestionGamme.listeGammes.get(i));
				return true;
			}
		}
		return false;
	}

	// Supprime une gamme a partir d'une reference
	public static boolean supprimerGamme(String reference){
		for(int i=0;i<commande.size();i++){
			if (reference.equals((String) commande.get(i).getReference())){
				commande.remove(i);
				return true;
			}
		}
		return false;
	}

	// Supprime une gamme a partir de sa position dans la commande
	public static boolean supprimerGamme(int pos){
		if (pos<commande.size()){
			commande.remove(pos);
			return true;
		}
		else return false;
	}
	

}
