require_relative "boot"

require "rails/all"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

# Ensure pagy is loaded
require 'pagy'

module BaffleHub
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 8.1

    # Please, add to the `ignore` list any other `lib` subdirectories that do
    # not contain `.rb` files, or that should not be reloaded or eager loaded.
    # Common ones are `templates`, `generators`, or `middleware`, for example.
    config.autoload_lib(ignore: %w[assets tasks])

    # Configure trusted proxies for proper client IP detection
    # This allows Rails to properly detect real client IPs behind reverse proxies
    config.action_dispatch.trusted_proxies = [
      # Docker network ranges where your reverse proxy might be
      IPAddr.new("172.16.0.0/12"),   # Docker default bridge network range
      IPAddr.new("10.0.0.0/8"),      # Internal networks
      IPAddr.new("192.168.0.0/16"),  # Private networks
      IPAddr.new("172.64.66.1")      # Your specific Caddy container IP
    ]

    # Enable IP spoofing check for security
    config.action_dispatch.ip_spoofing_check = true
  end
end
