# ==============================================
# DATASOURCE CONFIGURATION
# ==============================================
spring.datasource.url=jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:geosegbar_dev}
spring.datasource.username=${DB_USERNAME:postgres}
spring.datasource.password=${DB_PASSWORD:password}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

# ==============================================
# POOL DE CONEXÕES HIKARI
# ==============================================
spring.datasource.hikari.keepalive-time=120000
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=4
spring.datasource.hikari.connection-timeout=6000
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.max-lifetime=1200000
spring.datasource.hikari.leak-detection-threshold=30000
spring.jpa.properties.hibernate.connection.autocommit=false
spring.transaction.default-timeout=30
spring.datasource.hikari.auto-commit=false
spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true

# ==============================================
# TOMCAT CONFIGURATION
# ==============================================
server.port=${SERVER_PORT:9090}
server.tomcat.max-threads=60
server.tomcat.threads.min-spare=15
server.tomcat.accept-count=150
server.tomcat.max-connections=300
server.tomcat.connection-timeout=30000
server.tomcat.keep-alive-timeout=60000
server.tomcat.max-keep-alive-requests=500
server.tomcat.max-http-header-size=16384
server.tomcat.max-http-post-size=10485760
server.tomcat.min-spare-threads=10
server.tomcat.max-swallow-size=10485760
server.tomcat.processor-cache=60

# ==============================================
# JPA/HIBERNATE
# ==============================================
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.jdbc.batch_size=50
spring.jpa.properties.hibernate.cache.use_second_level_cache=false
spring.jpa.properties.hibernate.cache.use_query_cache=false
spring.jpa.properties.hibernate.bytecode.use_reflection_optimizer=false
spring.jpa.properties.hibernate.jdbc.time_zone=${TZ:America/Sao_Paulo}
spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true
spring.jpa.properties.hibernate.generate_statistics=false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=false

# ==============================================
# SECURITY
# ==============================================
api.security.token.secret=${JWT_SECRET:default_secret_change_this}

# ==============================================
# EMAIL CONFIGURATION
# ==============================================
spring.mail.host=${MAIL_HOST:localhost}
spring.mail.port=${MAIL_PORT:465}
spring.mail.username=${MAIL_USERNAME:noreply@localhost}
spring.mail.password=${MAIL_PASSWORD:password}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true
application.admin-email=joaocaetanodev@gmail.com

# ==============================================
# FILE STORAGE
# ==============================================
file.upload-dir=${FILE_UPLOAD_DIR:/tmp/uploads}
file.base-url=${FILE_BASE_URL:/storage/}
file.psb-dir=${FILE_PSB_DIR:${file.upload-dir}/psb}

# ==============================================
# FRONTEND
# ==============================================
application.frontend-url=${FRONTEND_URL:http://localhost:3000}

# ==============================================
# EXTERNAL API - ANA
# ==============================================
ana.api.identifier=${ANA_API_IDENTIFIER:}
ana.api.password=${ANA_API_PASSWORD:}
ana.api.auth-url=${ANA_API_AUTH_URL:https://www.ana.gov.br/hidrowebservice/EstacoesTelemetricas/OAUth/v1}
ana.api.telemetry-url=${ANA_API_TELEMETRY_URL:https://www.ana.gov.br/hidrowebservice/EstacoesTelemetricas/HidroinfoanaSerieTelemetricaAdotada/v1}

# ==============================================
# COMPRESSION
# ==============================================
server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
server.compression.min-response-size=2048

# ==============================================
# HTTP CONFIGURATION
# ==============================================
server.tomcat.reject-illegal-header=false
server.tomcat.relaxed-query-chars=|,{,},[,]
server.tomcat.relaxed-path-chars=|,{,},[,]
server.http.encoding.force=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true

spring.application.name=geosegbar-api

# Expor endpoints
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.prometheus.enabled=true
management.endpoint.health.probes.enabled=true

# Habilitar métricas Prometheus
management.metrics.export.prometheus.enabled=true

# Métricas detalhadas
management.metrics.enable.jvm=true
management.metrics.enable.process=true
management.metrics.enable.system=true
management.metrics.enable.tomcat=true
management.metrics.enable.http=true
management.metrics.enable.hikaricp=true

# Histogramas de latência (P50, P95, P99)
management.metrics.distribution.percentiles-histogram.http.server.requests=true
management.metrics.distribution.percentiles.http.server.requests=0.5,0.95,0.99
management.metrics.distribution.slo.http.server.requests=50ms,100ms,200ms,500ms,1s

# Tags customizadas
management.metrics.tags.application=${spring.application.name}
management.metrics.tags.environment=${SPRING_PROFILES_ACTIVE:dev}