package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.GeoBounds
import de.arxsilex.maptools.converter.core.MapFormatVersion
import java.nio.file.Path
import kotlin.test.Test

class RealMapsforgeCompatibilityTest {
    @Test
    fun `optional real output opens with the same reader version as MapTools`() {
        val file = System.getenv("MAPTOOLS_TEST_MAP")?.takeIf(String::isNotBlank) ?: return
        val bounds = System.getenv("MAPTOOLS_TEST_BOUNDS")
            ?.split(',')
            ?.map(String::toDouble)
            ?.takeIf { it.size == 4 }
            ?: error("MAPTOOLS_TEST_BOUNDS muss west,south,east,north enthalten.")
        val format = MapFormatVersion.entries.single {
            it.metadataVersion == (System.getenv("MAPTOOLS_TEST_MAP_VERSION") ?: "5").toInt()
        }

        ExportOutputValidator.validateMapsforgeMap(
            Path.of(file),
            GeoBounds(west = bounds[0], south = bounds[1], east = bounds[2], north = bounds[3]),
            format,
        )
    }
}
