package ch.epfl.isochrone.tiledmap;

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

import javax.imageio.ImageIO;

import org.junit.Test;

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.Service;
import ch.epfl.isochrone.timetable.Stop;
import ch.epfl.isochrone.timetable.TimeTable;
import ch.epfl.isochrone.timetable.TimeTableReader;
import ch.epfl.isochrone.timetable.Date.Month;

public class TestTransparentTileProvider {

    @Test
    public void testAccurateImage() throws IOException {
        
        TimeTableReader timeTableReader = new TimeTableReader("/time-table/");
        TimeTable timeTable = timeTableReader.readTimeTable();

        Stop departure = null;
        for (Stop s : timeTable.stops()) {
            if (s.name().equals("Lausanne-Flon")) {
                departure = s;
            }
        }

        Set<Service> services = timeTable.servicesForDate(new Date(1, Month.OCTOBER, 2013));
        Graph graph = timeTableReader.readGraphForServices(timeTable.stops(),
                services, 5 * 60, 1.25);

        FastestPathTree tree = graph.fastestPaths(departure, SecondsPastMidnight.fromHMS(6, 8, 0));
        
        List<Color> colorList = new ArrayList<Color>();
        colorList.add(new Color(255, 0, 0));
        colorList.add(new Color(255, 122, 0));
        colorList.add(new Color(255, 255, 0));
        colorList.add(new Color(122, 255, 0));
        colorList.add(new Color(0, 255, 0));
        colorList.add(new Color(0, 122, 122));
        colorList.add(new Color(0, 0, 255));
        colorList.add(new Color(0, 0, 122));
        colorList.add(new Color(0, 0, 0));
        ColorTable colorTable = new ColorTable(300, colorList);
        
        TransparentTileProvider tp1 = new TransparentTileProvider(0.5, new IsochroneTileProvider(tree, colorTable, 1.25));
        ImageIO.write(tp1.tileAt(11, 1061, 724).image(), "png", new File("imageIsoTransparent.png"));
        
        TransparentTileProvider tp2 = new TransparentTileProvider(0.5, new OSMTileProvider("http://b.tile.openstreetmap.org/"));
        ImageIO.write(tp2.tileAt(11, 1061, 724).image(), "png", new File("imageOSMTransparent.png"));
    }
}
