package de.assecutor.votianlt.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * Jackson configuration for consistent JSON serialization across the
 * application. Ensures all date/time fields are serialized as ISO 8601 strings.
 */
@Configuration
public class JacksonConfig {

    /**
     * Creates a configured ObjectMapper bean that serializes dates as ISO 8601
     * strings. This bean is used throughout the application for JSON serialization.
     */
    @Bean
    @Primary
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        // Serialize dates as ISO 8601 strings instead of timestamps/arrays
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        return objectMapper;
    }
}
