package eu.simstadt.regionchooser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;


class CRSfromCityGMLHeaderTests
{
	private Path repo = Paths.get("src/test/resources/testdata");

	private void testExtractCSRNameFromHeader(Path citygmlPath, String crsName) throws IOException {
		assertEquals(RegionChooserUtils.crsFromCityGMLHeader(citygmlPath).toString(), crsName);
	}

	@Test
	void testExtractCRSFromStuttgart() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("Stuttgart.proj/Stuttgart_LOD0_LOD1_buildings_and_trees.gml"),
				"EPSG:31463");
	}

	@Test
	void testExtractCRSFromGruenbuehl() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("Gruenbuehl.proj/20140218_Gruenbuehl_LOD2_1building.gml"),
				"EPSG:31467");
	}

	@Test
	void testExtractCRSFromMunich() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("Muenchen.proj/Munich_v_1_0_0.gml"), "EPSG:32632");
	}

	@Test
	void testExtractCRSFromNYC() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("NewYork.proj/ManhattanSmall.gml"), "EPSG:32118");
	}

	@Test
	void testExtractCRSFromAachen() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("Others.proj/Aachen_LoD2_293_5623_1_NW.gml"), "EPSG:25832");
	}

	@Test
	void testExtractCRSFromValladolid() throws IOException {
		testExtractCSRNameFromHeader(repo.resolve("Others.proj/Valladolid_Spain_only_header.gml"), "EPSG:25830");
	}

	@Test
	void testDontExtractCRSFromBrokenCityGML() throws IOException {
		Path citygmlPath = repo.resolve("Others.proj/SimpleSolid_MSBS.gml");
		assertThrows(IllegalArgumentException.class, () -> {
			testExtractCSRNameFromHeader(citygmlPath, "Nothing found. Should throw an exception");
		});
	}
}
