package space.nstart.pcp.complan.service

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import space.nstart.pcp.complan.db.repository.DynamicPlanRouteRepository
import space.nstart.pcp.complan.db.repository.DynamicPlanRunRepository

class SatelliteDeletedServiceTest {

    @Test
    fun `deleteSatelliteData removes dynamic plan runs and satellite routes`() {
        val runRepository = mock(DynamicPlanRunRepository::class.java)
        val routeRepository = mock(DynamicPlanRouteRepository::class.java)
        val service = SatelliteDeletedService(runRepository, routeRepository)

        `when`(runRepository.countBySatelliteId(56756L)).thenReturn(2L)
        `when`(routeRepository.countBySatelliteId(56756L)).thenReturn(5L)
        `when`(runRepository.deleteAllBySatelliteId(56756L)).thenReturn(2)
        `when`(routeRepository.deleteAllBySatelliteId(56756L)).thenReturn(1)

        val summary = service.deleteSatelliteData(56756L)

        assertEquals(56756L, summary.satelliteId)
        assertEquals(2, summary.runsDeleted)
        assertEquals(4L, summary.routesDeletedByRunCascade)
        assertEquals(1, summary.orphanRoutesDeleted)
        verify(runRepository).deleteAllBySatelliteId(56756L)
        verify(routeRepository).deleteAllBySatelliteId(56756L)
    }
}
