package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.GeoBounds
import de.arxsilex.maptools.converter.core.NormalizedMapArea
import de.arxsilex.maptools.converter.core.RectangleSelection
import de.arxsilex.maptools.converter.core.preview.PreviewDataset
import de.arxsilex.maptools.converter.core.preview.PreviewFeatureClass
import de.arxsilex.maptools.converter.core.preview.PreviewPoint
import de.arxsilex.maptools.converter.core.preview.PreviewPolyline
import kotlin.test.Test
import kotlin.test.assertEquals

class PreviewSelectionEstimatorTest {
    @Test
    fun `overlapping selections do not duplicate preview objects or estimates`() {
        val dataset = PreviewDataset(
            bounds = GeoBounds(8.0, 50.0, 8.2, 50.2),
            points = listOf(PreviewPoint(50.05, 8.05, PreviewFeatureClass.POI)),
            polylines = listOf(
                PreviewPolyline(
                    coordinates = doubleArrayOf(8.01, 50.01, 8.19, 50.19),
                    featureClass = PreviewFeatureClass.MAJOR_ROAD,
                ),
            ),
            sourceNodeCount = 900,
            sourceWayCount = 100,
        )
        val full = RectangleSelection(NormalizedMapArea.Full)

        val summary = PreviewSelectionEstimator.estimate(
            dataset = dataset,
            renderIndex = PreviewRenderIndex.build(dataset),
            shapes = listOf(full, full),
            sourceBounds = dataset.bounds,
            sourceSizeBytes = 1_000_000,
        )

        assertEquals(2, summary.areas.size)
        assertEquals(2, summary.total.previewObjectCount)
        assertEquals(1_000, summary.total.estimatedSourceObjectCount)
    }
}
