package space.nstart.pcp_tgu_service.service

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import space.nstart.pcp_tgu_service.repository.VisibilityRefreshJobRepository
import java.time.LocalDateTime
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes

/**
 * Coalesce-сервис для visibility_refresh_job по spacecraftId.
 */
@Service
class VisibilityRefreshJobService(
    private val visibilityRefreshJobRepository: VisibilityRefreshJobRepository
) {
    /** Ставит или переоткрывает refresh job без дублей. */
    @Transactional
    fun enqueue(spacecraftId: String, noradId: Long?, reason: String) {
        visibilityRefreshJobRepository.upsertPending(spacecraftId, noradId, reason, UtcDateTimes.now())
    }
}
