package com.graphhopper.jackson;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.graphhopper.GHResponse;

class PathDetailDeserializerTest {

	@Test
	public void else_null_detail_average_speed() throws JsonProcessingException {
		final ObjectMapper objectMapper = Jackson.newObjectMapper();
		final String result = "{\"hints\":{\"visited_nodes.sum\":90,\"visited_nodes.average\":90},\"info\":{\"copyrights\":[\"GraphHopper\",\"OpenStreetMap contributors\"],\"took\":1},\"paths\":[{\"distance\":9863.287,\"weight\":888.630785,\"time\":740658,\"transfers\":0,\"points_encoded\":false,\"bbox\":[-58.476658,-34.650384,-58.429018,-34.628717],\"points\":{\"type\":\"LineString\",\"coordinates\":[[-58.465985,-34.650384],[-58.465985,-34.650384],[-58.46555,-34.649904],[-58.465416,-34.649686],[-58.464935,-34.649033],[-58.464199,-34.648446],[-58.464014,-34.648262],[-58.463675,-34.647783],[-58.462575,-34.645549],[-58.462426,-34.645311],[-58.462031,-34.644079],[-58.461681,-34.643299],[-58.461561,-34.643099],[-58.461258,-34.642675],[-58.460623,-34.642013],[-58.460372,-34.641799],[-58.458082,-34.640102],[-58.456072,-34.638467],[-58.45555,-34.638104],[-58.453825,-34.637045],[-58.453518,-34.636894],[-58.453287,-34.636799],[-58.452854,-34.636647],[-58.452399,-34.636541],[-58.451783,-34.636477],[-58.451437,-34.636461],[-58.45096,-34.636455],[-58.449346,-34.636492],[-58.448718,-34.636475],[-58.448065,-34.636381],[-58.447576,-34.636252],[-58.447071,-34.636088],[-58.446624,-34.635893],[-58.445336,-34.635105],[-58.443767,-34.633999],[-58.441687,-34.632678],[-58.440299,-34.631866],[-58.439234,-34.631214],[-58.43877,-34.630985],[-58.437805,-34.630657],[-58.436974,-34.630468],[-58.434133,-34.630075],[-58.432415,-34.629923],[-58.430902,-34.629722],[-58.430437,-34.62966],[-58.430367,-34.629977],[-58.429018,-34.629782],[-58.429325,-34.628717],[-58.430635,-34.628917],[-58.430561,-34.62922],[-58.432879,-34.629618],[-58.434549,-34.629933],[-58.436946,-34.630326],[-58.437878,-34.630532],[-58.438762,-34.630822],[-58.439319,-34.63109],[-58.440885,-34.632045],[-58.442483,-34.632958],[-58.443484,-34.633603],[-58.445463,-34.634973],[-58.446519,-34.635643],[-58.446771,-34.635791],[-58.447069,-34.635926],[-58.447557,-34.636096],[-58.448078,-34.636254],[-58.44873,-34.636348],[-58.451367,-34.636297],[-58.452221,-34.636358],[-58.452712,-34.636448],[-58.453267,-34.636623],[-58.453552,-34.63673],[-58.453854,-34.636872],[-58.454214,-34.637075],[-58.455065,-34.637593],[-58.456306,-34.638427],[-58.457424,-34.639367],[-58.45823,-34.640018],[-58.460244,-34.641438],[-58.460783,-34.641844],[-58.461038,-34.642077],[-58.461295,-34.642353],[-58.461474,-34.64258],[-58.461901,-34.643196],[-58.462073,-34.643528],[-58.462269,-34.644017],[-58.462687,-34.645211],[-58.463101,-34.645982],[-58.463506,-34.646562],[-58.463782,-34.646898],[-58.464636,-34.647832],[-58.465174,-34.648395],[-58.4654,-34.648587],[-58.465807,-34.648882],[-58.466103,-34.649053],[-58.466435,-34.6492],[-58.466725,-34.649293],[-58.467056,-34.649351],[-58.467634,-34.649388],[-58.469992,-34.64935],[-58.47232,-34.64918],[-58.473264,-34.649091],[-58.474569,-34.648922],[-58.475036,-34.648843],[-58.475346,-34.648771],[-58.475799,-34.648596],[-58.476658,-34.648084]]},\"instructions\":[{\"distance\":3923.699,\"heading\":90,\"sign\":0,\"interval\":[0,41],\"text\":\"Continue na Autopista Teniente General Luis Dellepiane\",\"time\":228978,\"street_name\":\"Autopista Teniente General Luis Dellepiane\"},{\"distance\":341.449,\"sign\":7,\"interval\":[41,44],\"text\":\"Mantenha-se à direita\",\"time\":52395,\"street_name\":\"\"},{\"distance\":35.813,\"sign\":2,\"interval\":[44,45],\"text\":\"Vire à direita na Viel\",\"time\":7162,\"street_name\":\"Viel\"},{\"distance\":125.343,\"sign\":-2,\"interval\":[45,46],\"text\":\"Vire à esquerda na Tejedor\",\"time\":25068,\"street_name\":\"Tejedor\"},{\"distance\":121.839,\"sign\":-2,\"interval\":[46,47],\"text\":\"Vire à esquerda na Doblas\",\"time\":31329,\"street_name\":\"Doblas\"},{\"distance\":121.976,\"sign\":-2,\"interval\":[47,48],\"text\":\"Vire à esquerda na Zuviría\",\"time\":24395,\"street_name\":\"Zuviría\"},{\"distance\":34.367,\"sign\":-2,\"interval\":[48,49],\"text\":\"Vire à esquerda na Viel\",\"time\":6873,\"street_name\":\"Viel\"},{\"distance\":3623.263,\"sign\":2,\"interval\":[49,85],\"text\":\"Vire à direita\",\"time\":234503,\"street_name\":\"\"},{\"distance\":1535.538,\"sign\":7,\"interval\":[85,105],\"text\":\"Mantenha-se à direita\",\"time\":129955,\"street_name\":\"\"},{\"distance\":0,\"sign\":4,\"last_heading\":305.9709217557622,\"interval\":[105,105],\"text\":\"Destino alcançado!\",\"time\":0,\"street_name\":\"\"}],\"legs\":[],\"details\":{\"average_speed\":[[0,1,null],[1,2,16],[2,7,78],[7,41,64],[41,43,26],[43,44,14],[44,46,18],[46,47,14],[47,49,18],[49,51,26],[51,85,64],[85,96,40],[96,103,48],[103,105,32]]},\"ascend\":40.208499908447266,\"descend\":36.19799995422363,\"snapped_waypoints\":{\"type\":\"LineString\",\"coordinates\":[[-58.465985,-34.650384],[-58.476658,-34.648084]]}}]}";
		final GHResponse ghResponse = objectMapper.readValue(result, GHResponse.class);
		assertNotNull(ghResponse);
	}
}
