package org.josast.ModuleSatelliteDatabase;

import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

import org.josast.AmsatList.generated.AmsatList;
import org.josast.AmsatList.generated.Satellites;

public class CheckAmsatListFile {
    /**
     * Amsat list structure.
     */
    private AmsatList al = null;

    /**
     * @param file file name.
     */
    public CheckAmsatListFile(final String file) {
        AmsatListFile alf = new AmsatListFile();
        al = alf.openAmsatList(file);

    }

    /**
     * @return list of satellite.
     */
    public Vector<String> checkUniqueSatelliteName() {

        Hashtable<String, Satellites> amsatListSatellite = new Hashtable<String, Satellites>();

        List<Satellites> listSatellite = al.getSatellites();
        ListIterator<Satellites> it = listSatellite.listIterator();
        Vector<String> satNameVec = new Vector<String>();
        // vérifier qu'un satellite n'est pas deux fois dans la base

        while (it.hasNext()) {
            Satellites sat = it.next();
            String satelliteName = sat.getName();

            if (amsatListSatellite.containsKey(satelliteName)) {
                satNameVec.addElement(satelliteName);
            } else {
                amsatListSatellite.put(satelliteName, sat);
            }

        }
        return satNameVec;
    }

    /**
     * @return list of satellite name
     */
    public Vector<String> checkUniqueSatelliteNasaID() {

        Hashtable<Integer, Satellites> amsatListSatellite = new Hashtable<Integer, Satellites>();

        List<Satellites> listSatellite = al.getSatellites();
        ListIterator<Satellites> it = listSatellite.listIterator();
        Vector<String> satNameVec = new Vector<String>();
        // vérifier qu'un satellite n'est pas deux fois dans la base

        while (it.hasNext()) {
            Satellites sat = it.next();
            int satelliteId = sat.getNasaID();

            if (amsatListSatellite.containsKey(satelliteId)) {
                satNameVec.addElement(sat.getName() + " " + satelliteId);
            } else {
                amsatListSatellite.put(satelliteId, sat);
            }

        }
        return satNameVec;
    }

    /**
     * @return amsat List Satellite.
     */
    public Vector<String> getListSatelliteStatus() {
        Hashtable<String, Vector<Satellites>> amsatListSatellite = new Hashtable<String, Vector<Satellites>>();

        List<Satellites> listSatellite = al.getSatellites();
        Vector<String> satelliteStatus = new Vector<String>();

        ListIterator<Satellites> it = listSatellite.listIterator();
        while (it.hasNext()) {
            Satellites sat = it.next();
            String status = sat.getStatus();

            if (status == null) {
                System.out.println("Status Null");
                status = "Not Defined";

            }
            Vector<Satellites> vsat;
            if (amsatListSatellite.containsKey(status)) {
                vsat = amsatListSatellite.get(status);

            } else {
                vsat = new Vector<Satellites>();
                amsatListSatellite.put(status, vsat);
                satelliteStatus.add(status);
            }
            vsat.addElement(sat);
        }

        return satelliteStatus;
    }

}
