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.OSMTileProvider;
import ch.epfl.isochrone.tiledmap.Tile;
import ch.epfl.isochrone.tiledmap.TransparentTileProvider;
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 {

    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);
        
        
        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, 1.25).tileAt(11, 1061, 724);
        ImageIO.write(t.image(), "png", new File("image.png"));
        
        Tile t3 = new OSMTileProvider("http://a.tile.openstreetmap.org/").tileAt(11, 1061, 724);
        ImageIO.write(t3.image(),"png", new File("imgae3.png")); 
        
        TransparentTileProvider t2 = new TransparentTileProvider(0.5, new IsochroneTileProvider(f, ct, 1.25));
        t = t2.tileAt(11, 1061, 724);
        ImageIO.write(t.image(), "png", new File("image2.png"));
        
        
    }
}
