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.PlanDecisionMessage
import space.nstart.pcp_tgu_service.service.HandlePlanDecisionUseCase

/**
 * Kafka consumer decision events; вся бизнес-логика вынесена в use case.
 */
@Component
class PlanDecisionConsumer(
    val topicsProperties: TopicsProperties,
    private val handlePlanDecisionUseCase: HandlePlanDecisionUseCase
) {
    /** Делегирует ACCEPTED/REJECTED обработку по attemptId. */
    @KafkaListener(
        topics = ["#{__listener.topicsProperties.satellitePlanDecision}"],
        groupId = "\${spring.kafka.consumer.group-id}"
    )
    fun consume(message: PlanDecisionMessage) {
        handlePlanDecisionUseCase.handle(message)
    }
}
