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

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class PreviewFeatureClassifierTest {
    @Test
    fun `keeps major roads without sampling`() {
        assertEquals(
            PreviewFeatureClass.MAJOR_ROAD,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "primary"), 17),
        )
    }

    @Test
    fun `keeps minor paths so zoom can decide their visibility`() {
        assertEquals(
            PreviewFeatureClass.PATH,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "path"), 97),
        )
        assertEquals(
            PreviewFeatureClass.PATH,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "steps"), 98),
        )
        assertEquals(
            PreviewFeatureClass.PATH,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "pedestrian"), 99),
        )
    }

    @Test
    fun `separates regional roads from local streets`() {
        assertEquals(
            PreviewFeatureClass.MINOR_ROAD,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "tertiary"), 100),
        )
        assertEquals(
            PreviewFeatureClass.LOCAL_ROAD,
            PreviewFeatureClassifier.classifyWay(mapOf("highway" to "residential"), 101),
        )
    }

    @Test
    fun `recognizes sampled poi tags`() {
        assertTrue(PreviewFeatureClassifier.isPoi(mapOf("amenity" to "bench"), 84))
    }

    @Test
    fun `separates water and urban areas from green land`() {
        assertEquals(
            PreviewFeatureClass.WATER_AREA,
            PreviewFeatureClassifier.classifyWay(mapOf("natural" to "water"), 48),
        )
        assertEquals(
            PreviewFeatureClass.URBAN_AREA,
            PreviewFeatureClassifier.classifyWay(mapOf("landuse" to "residential"), 48),
        )
    }

    @Test
    fun `prioritizes named settlements`() {
        assertEquals(
            PreviewLabelClass.CITY to 100,
            PreviewFeatureClassifier.nodeLabel(mapOf("place" to "city", "name" to "Wiesbaden")),
        )
    }

    @Test
    fun `stitches multipolygon members independent of direction`() {
        val rings = PreviewDatasetBuilder.stitchClosedRings(
            listOf(
                longArrayOf(1, 2, 3),
                longArrayOf(5, 4, 3),
                longArrayOf(5, 1),
            ),
        )

        assertEquals(1, rings.size)
        assertTrue(rings.single().contentEquals(longArrayOf(1, 2, 3, 4, 5, 1)))
    }
}
