# typed: false

require 'datadog/tracing/contrib/integration'

require 'datadog/tracing/contrib/rails/ext'
require 'datadog/tracing/contrib/rails/configuration/settings'
require 'datadog/tracing/contrib/rails/patcher'

module Datadog
  module Tracing
    module Contrib
      module Rails
        # Description of Rails integration
        class Integration
          include Contrib::Integration

          MINIMUM_VERSION = Gem::Version.new('3.2')

          # @public_api Changing the integration name or integration options can cause breaking changes
          register_as :rails, auto_patch: false

          def self.version
            Gem.loaded_specs['railties'] && Gem.loaded_specs['railties'].version
          end

          def self.loaded?
            !defined?(::Rails).nil?
          end

          def self.compatible?
            super && version >= MINIMUM_VERSION
          end

          def self.patchable?
            super && !ENV.key?(Ext::ENV_DISABLE)
          end

          def new_configuration
            Configuration::Settings.new
          end

          def patcher
            Patcher
          end
        end
      end
    end
  end
end
