require "active_support/core_ext/integer/time"

Rails.application.configure do
  config.enable_reloading = false
  config.eager_load = true
  config.consider_all_requests_local = false

  # HTTPS obrigatório: redireciona HTTP→HTTPS e marca cookies como "Secure".
  # assume_ssl faz o Rails confiar no TLS terminado no Cloudflare (que envia
  # X-Forwarded-Proto=https), evitando loop de redirecionamento.
  config.assume_ssl = true
  config.force_ssl  = true
  config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
  config.log_tags  = [:request_id]
  config.logger    = ActiveSupport::Logger.new(STDOUT).tap { |l| l.formatter = ::Logger::Formatter.new }
                                          .then { |l| ActiveSupport::TaggedLogging.new(l) }

  config.cache_store = :memory_store
  config.active_storage.service = :local if defined?(ActiveStorage)

  config.action_mailer.perform_caching = false
  config.action_mailer.default_url_options = { host: ENV.fetch("APP_HOST", "localhost:3000") }

  config.i18n.fallbacks = true
  config.active_support.report_deprecations = false
  config.active_record.dump_schema_after_migration = false

  # Aceita o host configurado no .env
  config.hosts << ENV["APP_HOST"]&.split(":")&.first if ENV["APP_HOST"].present?
  config.hosts.clear if ENV["RAILS_ALLOW_ALL_HOSTS"] == "true"
end
