package ch.epfl.isochrone;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

import ch.epfl.isochrone.tiledmap.ColorTable;
import ch.epfl.isochrone.tiledmap.IsochroneTileProvider;
import ch.epfl.isochrone.tiledmap.Tile;
import ch.epfl.isochrone.timetable.Date;
import ch.epfl.isochrone.timetable.FastestPathTree;
import ch.epfl.isochrone.timetable.Graph;
import ch.epfl.isochrone.timetable.SecondsPastMidnight;
import ch.epfl.isochrone.timetable.Stop;
import ch.epfl.isochrone.timetable.TimeTable;
import ch.epfl.isochrone.timetable.TimeTableReader;

/**
 * Classe Servant à tester le programme et à les affichés les premières heures
 * d'arrivée.
 * 
 * @author Charles Thiebaut (238935)
 * @author Arnaud Delamare (234841)
 * 
 */
public class TimeTableSearch {
    
    /**
     * Méthode main servant à tester les premieres classes du projet
     * 
     * @param args[0]
     *        le nom de l'arret
     * @param args[1]
     *        la date du jour désiré
     * @param args[2]
     *        l'heure
     */
    public static void main(String[] args) throws IOException {
        String stopName = 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(stopName)) {
                departure = s;
            }
        }

        Graph g = ttr.readGraphForServices(tt.stops(),
                tt.servicesForDate(date), 300, 1.25);

        FastestPathTree f = g.fastestPaths(departure, heure);
        
        
        List<Color> liste = new ArrayList<Color>();
        liste.add(new Color(255 ,0 ,0));
        liste.add(new Color(255 ,122 ,0));
        liste.add(new Color(255 ,255 ,0));
        liste.add(new Color(122 ,255 ,0));
        liste.add(new Color(0 ,255 ,0));
        liste.add(new Color(0 ,122 ,122));
        liste.add(new Color(0 ,0 ,255));
        liste.add(new Color(0 ,0 ,122));
        liste.add(new Color(0 ,0 ,0));
        ColorTable ct = new ColorTable(300,liste);
        
        Tile t = new IsochroneTileProvider(f, ct, 2.5).tileAt(11, 1061, 724);
        ImageIO.write(t.image(), "png", new File("image.png"));
    }
}
