module Selenium
  module WebDriver
    module Firefox
      module Driver
        class << self

          #
          # Instantiates correct Firefox driver implementation
          # @return [Marionette::Driver, Legacy::Driver]
          #

          def new(**opts)
            if marionette?(opts)
              Firefox::Marionette::Driver.new(opts)
            else
              Firefox::Legacy::Driver.new(opts)
            end
          end

          private

          def marionette?(opts)
            opts.delete(:marionette) != false &&
              (!opts[:desired_capabilities] || opts[:desired_capabilities][:marionette] != false)
          end
        end

      end # Driver
    end # Firefox
  end # WebDriver
end # Selenium
