package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.InputFormat
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import kotlin.io.path.createTempDirectory
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class ElevationInputInspectionTest {
    @Test
    fun `desktop import enriches elevation source with raster metadata`() {
        val directory = createTempDirectory("maptools-elevation-import-test")
        val source = directory.resolve("terrain.asc")
        try {
            Files.writeString(
                source,
                """
                ncols 3
                nrows 2
                xllcorner 8.0
                yllcorner 50.0
                cellsize 0.01
                NODATA_value -9999
                1 2 3
                4 5 6
                """.trimIndent(),
                StandardCharsets.US_ASCII,
            )

            val result = inspectInputFile(source.toFile())

            assertTrue(result.isSuccess)
            val input = result.getOrThrow()
            assertEquals(InputFormat.ELEVATION_ASC, input.format)
            assertNotNull(input.elevationMetadata)
            assertEquals(8.03, input.bounds?.east ?: Double.NaN, 0.000_000_1)
        } finally {
            directory.toFile().deleteRecursively()
        }
    }
}
