package space.nstart.pcp.routepassportconsumer.config

import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.common.serialization.StringSerializer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.kafka.core.DefaultKafkaProducerFactory

class KafkaProducerConfigTest {

    @Test
    fun `producer factory applies reliability settings`() {
        val config = KafkaProducerConfig(
            bootstrapServers = "localhost:9092",
            acks = "all",
            retries = 10,
            enableIdempotence = true,
            maxInFlightRequestsPerConnection = 5,
        )

        @Suppress("UNCHECKED_CAST")
        val producerFactory = config.producerFactory() as DefaultKafkaProducerFactory<String, String>
        val properties = producerFactory.configurationProperties

        assertThat(properties)
            .containsEntry(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092")
            .containsEntry(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer::class.java)
            .containsEntry(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer::class.java)
            .containsEntry(ProducerConfig.ACKS_CONFIG, "all")
            .containsEntry(ProducerConfig.RETRIES_CONFIG, 10)
            .containsEntry(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true)
            .containsEntry(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, 5)
    }
}
