package space.nstart.pcp.pcp_mission_planing_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_mission_planing_service.repository.MissionRepository
import space.nstart.pcp.pcp_mission_planing_service.repository.ModeRepository
import space.nstart.pcp.pcp_mission_planing_service.repository.PlanRepository

class SatelliteDeletedServiceTest {

    @Test
    fun `deleteSatelliteData removes missions and cascaded plans and modes`() {
        val missionRepository = mock(MissionRepository::class.java)
        val planRepository = mock(PlanRepository::class.java)
        val modeRepository = mock(ModeRepository::class.java)
        val service = SatelliteDeletedService(missionRepository, planRepository, modeRepository)

        `when`(missionRepository.countBySatelliteId(56756L)).thenReturn(2L)
        `when`(planRepository.countByMissionSatelliteId(56756L)).thenReturn(3L)
        `when`(modeRepository.countByPlan_Mission_SatelliteId(56756L)).thenReturn(5L)
        `when`(missionRepository.deleteAllBySatelliteId(56756L)).thenReturn(2L)

        val summary = service.deleteSatelliteData(56756L)

        assertEquals(56756L, summary.satelliteId)
        assertEquals(2L, summary.missionsDeleted)
        assertEquals(3L, summary.plansDeletedByCascade)
        assertEquals(5L, summary.modesDeletedByCascade)
        verify(missionRepository).deleteAllBySatelliteId(56756L)
    }
}
