package org.josast.AmsatList.check;

import java.util.Enumeration;
import java.util.Vector;

import org.josast.AmsatList.Commande.Commande;
import org.josast.ModuleSatelliteDatabase.FlatSatList;
import org.josast.ModuleSatelliteDatabase.FlatSatellite;

public class TwoListCompare {

	public Vector<Commande> compareNoradId(FlatSatList ref, FlatSatList tocomp) {
		Vector<Commande> listeCommande = new Vector<Commande>();

		Enumeration<Integer> idSat = tocomp.keys();
		while (idSat.hasMoreElements()) {
			Integer key = (Integer) idSat.nextElement();

			FlatSatellite fsat = ref.get(key);
			FlatSatellite flatSatelliteRef = tocomp.get(key);

			if (fsat == null) {
				Commande cmd = new Commande(flatSatelliteRef.getSatelliteName(), flatSatelliteRef.getSatelliteNoradId(),
						Commande.NasaIDUpdate, "0", "" + flatSatelliteRef.getSatelliteNoradId(), "norad Id not found");
				listeCommande.add(cmd);
			}
		}
		return listeCommande;
	}

	public Vector<Commande> compareIARUCoordination(FlatSatList ref, FlatSatList tocomp) {
		Vector<Commande> listeCommande = new Vector<Commande>();

		Enumeration<Integer> idSat = tocomp.keys();

		while (idSat.hasMoreElements()) {
			Integer key = (Integer) idSat.nextElement();

			FlatSatellite fsat = ref.get(key);
			FlatSatellite FlatSatelliteRef = tocomp.get(key);

			if (fsat != null) {
				if (FlatSatelliteRef.isIARUCoordination() != fsat.isIARUCoordination()) {
					Commande cmd = new Commande(FlatSatelliteRef.getSatelliteName(),
							FlatSatelliteRef.getSatelliteNoradId(), Commande.IARUCoordinationUpdate,
							" " + fsat.isIARUCoordination(), "" + FlatSatelliteRef.isIARUCoordination(),
							"IARU Coordination Update");
					listeCommande.add(cmd);
				}

			}

		}
		return listeCommande;
	}

	public Vector<Commande> compareSatelliteStatus(FlatSatList ref, FlatSatList tocomp) {
		Vector<Commande> listeCommande = new Vector<Commande>();

		Enumeration<Integer> idSat = tocomp.keys();

		while (idSat.hasMoreElements()) {
			Integer key = (Integer) idSat.nextElement();

			FlatSatellite FlatSatelliteRef = ref.get(key);
			FlatSatellite FlatSatellitetoComp = tocomp.get(key);

			if ((FlatSatellitetoComp != null) && (FlatSatelliteRef!=null)) {
				
				String refStatus = FlatSatelliteRef.getSatelliteStatus();
				String compStatus = FlatSatellitetoComp.getSatelliteStatus();
				if ((refStatus != null) & (compStatus != null)) {
					if (refStatus.compareTo(compStatus) != 0) {
						Commande cmd = new Commande(FlatSatelliteRef.getSatelliteName(),
								FlatSatelliteRef.getSatelliteNoradId(), Commande.SatelliteStatusUpdate, refStatus,
								compStatus, "Satellite status from :  " + refStatus + " to " + compStatus);
						listeCommande.add(cmd);
					}
				}

			}

		}
		return listeCommande;
	}
}
