package de.arxsilex.maptools.converter.worker

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

class PoiMergeRequestTest {
    @Test
    fun `parses repeated poi inputs with their schemas`() {
        val directory = createTempDirectory("poi-merge-request")
        try {
            val first = Files.createFile(directory.resolve("a.poi"))
            val second = Files.createFile(directory.resolve("b.poi"))
            val request = PoiMergeRequest.parse(
                arrayOf(
                    "poi-merge",
                    "--input", first.toString(), "--source-schema", "3",
                    "--input", second.toString(), "--source-schema", "4",
                    "--output", directory.resolve("merged.poi").toString(),
                    "--target-schema", "4",
                    "--temp-dir", directory.resolve("temp").toString(),
                    "--areas", "r,7.0,49.0,10.0,52.0",
                ),
            )

            assertEquals(listOf(PoiSchemaVersion.V3, PoiSchemaVersion.V4), request.sources.map { it.schema })
            assertEquals(listOf(first, second), request.sources.map { it.path })
            assertEquals(PoiSchemaVersion.V4, request.targetSchema)
            assertEquals(2, request.sources.size)
        } finally {
            directory.toFile().deleteRecursively()
        }
    }
}
