package space.nstart.pcp.slots_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.slots_service.repository.BookedSlotsRepository
import space.nstart.pcp.slots_service.repository.SatelliteIcRepository
import space.nstart.pcp.slots_service.repository.SlotRepository

class SatelliteDeletedServiceTest {

    @Test
    fun `deleteSatelliteData removes slots and initial conditions`() {
        val slotRepository = mock(SlotRepository::class.java)
        val bookedSlotsRepository = mock(BookedSlotsRepository::class.java)
        val satelliteIcRepository = mock(SatelliteIcRepository::class.java)
        val service = SatelliteDeletedService(slotRepository, bookedSlotsRepository, satelliteIcRepository)

        `when`(bookedSlotsRepository.countBySlot_SatelliteId(56756L)).thenReturn(3L)
        `when`(slotRepository.countBySatelliteId(56756L)).thenReturn(10L)
        `when`(slotRepository.deleteBySatId(56756L)).thenReturn(10)
        `when`(satelliteIcRepository.deleteBySatelliteId(56756L)).thenReturn(1)

        val summary = service.deleteSatelliteData(56756L)

        assertEquals(56756L, summary.satelliteId)
        assertEquals(10, summary.slotsDeleted)
        assertEquals(3L, summary.bookedSlotsDeletedByCascade)
        assertEquals(1, summary.initialConditionsDeleted)
        verify(slotRepository).deleteBySatId(56756L)
        verify(satelliteIcRepository).deleteBySatelliteId(56756L)
    }
}
