package space.nstart.pcp.pcp_coverage_scheme_service.service

import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GeometrySupportTest {

    private val geometrySupport = GeometrySupport()

    @Test
    fun `resolveLongitudeModel uses standard band when polygon crosses zero meridian`() {
        val model = geometrySupport.resolveLongitudeModel(
            "POLYGON ((-1 0, 1 0, 1 1, -1 1, -1 0))"
        )

        assertEquals(GeometrySupport.LongitudeModel.STANDARD_180, model)
    }

    @Test
    fun `resolveLongitudeModel uses positive band when polygon crosses one hundred eighty meridian`() {
        val model = geometrySupport.resolveLongitudeModel(
            "POLYGON ((179 0, -179 0, -179 1, 179 1, 179 0))"
        )

        assertEquals(GeometrySupport.LongitudeModel.POSITIVE_360, model)
    }

    @Test
    fun `parseAndNormalizeTarget keeps zero crossing polygon in standard band`() {
        val geometry = geometrySupport.parseAndNormalizeTarget(
            "POLYGON ((-1 0, 1 0, 1 1, -1 1, -1 0))",
            GeometrySupport.LongitudeModel.STANDARD_180
        )

        assertTrue(geometry.coordinates.all { it.x in -180.0..180.0 })
    }
}
