package space.nstart.pcp.pcp_satellites_service.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.pcp_satellites_service.repository.ComplexPlanRunSatelliteRepository
import space.nstart.pcp.pcp_satellites_service.repository.SatelliteModeRepository
import space.nstart.pcp.pcp_satellites_service.repository.SatelliteModeSnapshotRepository

class SatelliteDeletedServiceTest {

    @Test
    fun `deleteSatelliteData removes complex mission satellite data`() {
        val snapshotRepository = mock(SatelliteModeSnapshotRepository::class.java)
        val modeRepository = mock(SatelliteModeRepository::class.java)
        val runSatelliteRepository = mock(ComplexPlanRunSatelliteRepository::class.java)
        val service = SatelliteDeletedService(snapshotRepository, modeRepository, runSatelliteRepository)

        `when`(modeRepository.countBySatelliteId(56756L)).thenReturn(12L)
        `when`(snapshotRepository.countBySatelliteId(56756L)).thenReturn(3L)
        `when`(runSatelliteRepository.countBySatelliteId(56756L)).thenReturn(2L)
        `when`(snapshotRepository.deleteAllBySatelliteId(56756L)).thenReturn(3L)
        `when`(runSatelliteRepository.deleteAllBySatelliteId(56756L)).thenReturn(2L)

        val summary = service.deleteSatelliteData(56756L)

        assertEquals(56756L, summary.satelliteId)
        assertEquals(3L, summary.snapshotsDeleted)
        assertEquals(12L, summary.modesDeletedByCascade)
        assertEquals(2L, summary.runLinksDeleted)
        verify(snapshotRepository).deleteAllBySatelliteId(56756L)
        verify(runSatelliteRepository).deleteAllBySatelliteId(56756L)
    }
}
