package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.preview.PreviewFeatureClass
import de.arxsilex.maptools.converter.core.preview.PreviewLabel
import de.arxsilex.maptools.converter.core.preview.PreviewLabelClass
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class PreviewLayerPolicyTest {
    @Test
    fun `overview hides enabled detail layers until their useful zoom`() {
        val layers = PreviewLayerVisibility()

        assertTrue(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.MAJOR_ROAD, layers, 1f, false))
        assertFalse(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.MINOR_ROAD, layers, 1f, false))
        assertTrue(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.PATH, layers, 20f, false))
        assertTrue(
            PreviewLayerPolicy.isLabelVisible(
                PreviewLabel(50.0, 8.0, "Stadt", PreviewLabelClass.CITY, 100),
                layers,
                1f,
            ),
        )
        assertFalse(
            PreviewLayerPolicy.isLabelVisible(
                PreviewLabel(50.0, 8.0, "Dorf", PreviewLabelClass.VILLAGE, 78),
                layers,
                1f,
            ),
        )
    }

    @Test
    fun `enabled details appear only at their useful zoom`() {
        val layers = PreviewLayerVisibility(
            regionalRoads = true,
            localRoads = true,
            paths = true,
            buildings = true,
            poi = true,
        )

        assertFalse(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.LOCAL_ROAD, layers, 3f, false))
        assertTrue(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.LOCAL_ROAD, layers, 4f, false))
        assertFalse(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.PATH, layers, 6f, false))
        assertTrue(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.PATH, layers, 8f, false))
        assertFalse(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.BUILDING, layers, 12f, true))
        assertTrue(PreviewLayerPolicy.isFeatureVisible(PreviewFeatureClass.BUILDING, layers, 12f, false))
    }
}
