package space.nstart.pcp.tle_monitoring_service.service

import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import space.nstart.pcp.tle_monitoring_service.repository.TLERepository

@Service
class SatelliteDeletedService(
    private val tleRepository: TLERepository
) {

    private val logger = LoggerFactory.getLogger(this::class.java)

    @Transactional
    fun deleteSatelliteData(satelliteId: Long): Long {
        val beforeDelete = tleRepository.countBySatelliteId(satelliteId)
        val deleted = tleRepository.deleteAllBySatelliteId(satelliteId)
        logger.info(
            "Deleted TLE data for satellite: satelliteId={}, tleBeforeDelete={}, tleDeleted={}",
            satelliteId,
            beforeDelete,
            deleted
        )
        return deleted
    }
}
