package de.arxsilex.maptools.converter.core.preview

import de.arxsilex.maptools.converter.core.GeoBounds
import kotlin.test.Test
import kotlin.test.assertEquals

class PreviewDatasetCombinerTest {
    @Test
    fun `combines adjacent previews and removes overlap duplicates`() {
        val sharedRoad = PreviewPolyline(
            doubleArrayOf(8.4, 50.4, 8.6, 50.6),
            PreviewFeatureClass.MAJOR_ROAD,
        )
        val sharedPoi = PreviewPoint(50.5, 8.5, PreviewFeatureClass.POI)
        val sharedLabel = PreviewLabel(50.5, 8.5, "Grenzort", PreviewLabelClass.VILLAGE, 78)
        val first = PreviewDataset(
            bounds = GeoBounds(8.0, 50.0, 8.6, 51.0),
            points = listOf(sharedPoi),
            polylines = listOf(sharedRoad),
            sourceNodeCount = 100,
            sourceWayCount = 20,
            labels = listOf(sharedLabel),
        )
        val second = PreviewDataset(
            bounds = GeoBounds(8.4, 50.0, 9.0, 51.0),
            points = listOf(sharedPoi, PreviewPoint(50.7, 8.8, PreviewFeatureClass.POI)),
            polylines = listOf(sharedRoad),
            sourceNodeCount = 120,
            sourceWayCount = 30,
            labels = listOf(sharedLabel),
        )

        val combined = PreviewDatasetCombiner.combine(
            GeoBounds(8.0, 50.0, 9.0, 51.0),
            listOf(first, second),
        )

        assertEquals(2, combined.points.size)
        assertEquals(1, combined.polylines.size)
        assertEquals(1, combined.labels.size)
        assertEquals(220, combined.sourceNodeCount)
        assertEquals(50, combined.sourceWayCount)
    }
}
