package space.nstart.pcp_tgu_service.config

/** Настраивает Jackson-сериализацию для payload'ов клиента Camunda. */
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import io.camunda.client.api.JsonMapper as CamundaJsonMapper
import io.camunda.client.impl.CamundaObjectMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class CamundaJacksonConfig {

    /**
     * The service code still depends on Jackson 2 APIs, while the shared Boot 4 stack
     * auto-configures Jackson 3 for WebFlux. Keep a dedicated Jackson 2 mapper for
     * internal parsing and Camunda payloads until the module is migrated.
     */
    @Bean
    fun objectMapper(): ObjectMapper {
        return JsonMapper.builder()
            .addModule(KotlinModule.Builder().build())
            .addModule(JavaTimeModule())
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .build()
    }

    /** Создаёт JSON mapper для Camunda с поддержкой Kotlin-классов и Java time типов. */
    @Bean("camundaJsonMapper")
    fun camundaJsonMapper(objectMapper: ObjectMapper): CamundaJsonMapper {
        return CamundaObjectMapper(objectMapper)
    }
}
