package br.gov.sigefp.api;

import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.util.TimeZone;

/**
 * Classe principal da aplicação Spring Boot.
 * Configurada para Guiné-Bissau com timezone e locale apropriados.
 */
@SpringBootApplication
@EnableCaching
@EntityScan(basePackages = "br.gov.sigefp")
@EnableJpaRepositories(basePackages = "br.gov.sigefp")
@ComponentScan(basePackages = "br.gov.sigefp")
public class SigefpApplication {

    public static void main(String[] args) {
        // Configurar timezone padrão para Guiné-Bissau antes de iniciar a aplicação
        TimeZone.setDefault(TimeZone.getTimeZone("Africa/Bissau"));
        SpringApplication.run(SigefpApplication.class, args);
    }

    @PostConstruct
    public void init() {
        // Garantir que o timezone está configurado corretamente
        TimeZone.setDefault(TimeZone.getTimeZone("Africa/Bissau"));
        System.setProperty("user.timezone", "Africa/Bissau");
    }
}
