package space.nstart.pcp.complan.apl

import space.nstart.pcp.pcp_types_lib.dto.ballistics.OrbPointDTO
import java.time.LocalDateTime
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class CaptureAngleCalculatorTest {

    private val calculator = CaptureAngleCalculator()

    @Test
    fun `calculates capture angle from route width and orbital height`() {
        val angle = calculator.calculateCaptureAngle(
            routeWidthKm = 30.0,
            points = listOf(orbPoint(radiusMeters = 6_378_136.0 + 516_000.0))
        )

        assertEquals(1.665, angle!!, absoluteTolerance = 0.001)
    }

    @Test
    fun `returns null for empty points`() {
        assertNull(calculator.calculateCaptureAngle(routeWidthKm = 30.0, points = emptyList()))
    }

    @Test
    fun `returns null for non positive route width`() {
        assertNull(calculator.calculateCaptureAngle(routeWidthKm = 0.0, points = listOf(orbPoint())))
    }

    private fun orbPoint(radiusMeters: Double = 6_894_136.0) = OrbPointDTO(
        time = LocalDateTime.of(2026, 4, 30, 0, 0),
        revolution = 1L,
        x = radiusMeters,
        y = 0.0,
        z = 0.0,
        vx = 0.0,
        vy = 0.0,
        vz = 0.0
    )
}
