package de.arxsilex.maptools.converter.worker

import de.arxsilex.maptools.converter.core.PoiSchemaVersion
import de.arxsilex.maptools.converter.core.GeoRectangleRegion
import java.nio.file.Files
import kotlin.test.Test
import kotlin.test.assertEquals

class PoiConvertRequestTest {
    @Test
    fun `parses direct poi schema conversion`() {
        val input = Files.createTempFile("poi-convert", ".poi")
        val output = input.resolveSibling("converted-${System.nanoTime()}.poi")
        try {
            val request = PoiConvertRequest.parse(
                arrayOf(
                    "poi-convert",
                    "--input", input.toString(),
                    "--output", output.toString(),
                    "--source-schema", "3",
                    "--target-schema", "4",
                    "--areas", "r,8.0,50.0,9.0,51.0",
                ),
            )
            assertEquals(PoiSchemaVersion.V3, request.sourceSchema)
            assertEquals(PoiSchemaVersion.V4, request.targetSchema)
            assertEquals(output.toAbsolutePath().normalize(), request.output)
            assertEquals(1, request.areas?.size)
            assertEquals(8.0, (request.areas?.single() as GeoRectangleRegion).bounds.west)
        } finally {
            Files.deleteIfExists(output)
            Files.deleteIfExists(input)
        }
    }
}
