package ch.epfl.isochrone;
import java.io.IOException;

import ch.epfl.isochrone.timetable.Date;
import ch.epfl.isochrone.timetable.FastestPathTree;
import ch.epfl.isochrone.timetable.Graph;
import ch.epfl.isochrone.timetable.GraphEdge;
import ch.epfl.isochrone.timetable.SecondsPastMidnight;
import ch.epfl.isochrone.timetable.Service;
import ch.epfl.isochrone.timetable.Stop;
import ch.epfl.isochrone.timetable.TimeTable;
import ch.epfl.isochrone.timetable.TimeTableReader;

/**
 * Classe servant à tester les différentes classes
 * 
 * @author Charles Thiebaut (238935) 
 * @author Arnaud Delamare (234841)
 *
 */
public class TimeTableSearch {

    public static void main(String[] args) throws IOException {
        String nomArret = args[0];
        Stop departure = null; 
        
        String[] champs1 = args[1].split("-");
        String[] champs2 = args[2].split(":");
        Date date = new Date(Integer.parseInt(champs1[2]), Integer.parseInt(champs1[1]), Integer.parseInt(champs1[0]));
        int heure = SecondsPastMidnight.fromHMS(Integer.parseInt(champs2[0]), Integer.parseInt(champs2[1]), Integer.parseInt(champs2[2]));
        
        
        TimeTableReader ttr = new TimeTableReader("/time-table/");
        TimeTable tt = ttr.readTimeTable();
        
        for(Stop s: tt.stops())
        {
            if(s.name().equals(nomArret))
            {
                departure = s;
            }
        }
        
        Graph g = ttr.readGraphForServices(tt.stops(), tt.servicesForDate(date), 300, 1.25);
        
        FastestPathTree f = g.fastestPaths(departure, heure);
        
        for (Stop s : tt.stops())
        {
            if (f.arrivalTime(s)<SecondsPastMidnight.INFINITE)
            {
                System.out.println("Arrivée à " + s.name() + " : " + SecondsPastMidnight.toString(f.arrivalTime(s)));
                System.out.println("via : " + f.pathTo(s));
            }
        }
    }
}
