package space.nstart.pcp_tgu_service.integration.kafka

import org.springframework.kafka.annotation.KafkaListener
import org.springframework.stereotype.Component
import space.nstart.pcp_tgu_service.config.TopicsProperties
import space.nstart.pcp_tgu_service.dto.PlanExecutionFeedbackMessage
import space.nstart.pcp_tgu_service.service.HandlePlanDecisionUseCase

/**
 * Kafka consumer события «не заложен»; делегирует срочную перевыдачу в use case.
 */
@Component
class LayinFailedConsumer(
    val topicsProperties: TopicsProperties,
    private val handlePlanDecisionUseCase: HandlePlanDecisionUseCase
) {
    @KafkaListener(
        topics = ["#{__listener.topicsProperties.layinFailed}"],
        groupId = "\${spring.kafka.consumer.group-id}"
    )
    fun consume(message: PlanExecutionFeedbackMessage) {
        handlePlanDecisionUseCase.handleLayinFailed(message)
    }
}
