package br.gov.sigefp.api.config;

import br.gov.sigefp.common.util.GuineaBissauConfig;
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;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import java.time.ZoneId;
import java.util.Locale;
import java.util.TimeZone;

/**
 * Configuração do Jackson para formatação de JSON compatível com Guiné-Bissau.
 */
@Configuration
public class JacksonConfig {

    @Bean
    @Primary
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.build();
        
        // Configurar timezone
        objectMapper.setTimeZone(TimeZone.getTimeZone(GuineaBissauConfig.TIMEZONE));
        
        // Configurar locale
        objectMapper.setLocale(GuineaBissauConfig.LOCALE);
        
        // Configurar módulo de datas Java 8+
        JavaTimeModule javaTimeModule = new JavaTimeModule();
        objectMapper.registerModule(javaTimeModule);
        
        // Não serializar datas como timestamps
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        
        // Não serializar valores null
        objectMapper.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);
        
        return objectMapper;
    }
}


