# frozen_string_literal: true

#
# Routes constraints for Ad routes
#
class AdConstraint
  def matches?(request)
    params = request.path_parameters

    return false unless valid_combination?(params[:type], params[:status])

    true
  end

  private

  def valid_combination?(type, status)
    # rubocop:disable Style/WordArray
    [
      [nil, nil],
      ['want', nil],
      ['give', nil],
      ['give', 'available'],
      ['give', 'booked'],
      ['give', 'delivered']
    ].include?([type, status])
    # rubocop:enable Style/WordArray
  end
end

# frozen_string_literal: true

#
# Routes constraints for Ad routes
#
class AdConstraint
  def matches?(request)
    params = request.path_parameters

    return false unless valid_combination?(params[:controller], params[:type], params[:status])

    true
  end

  private

  def valid_combination?(controller, type, status)
    # rubocop:disable Style/WordArray
    [
      ['users', nil, nil],
      ['users', 'want', nil],
      ['users', 'give', nil],
      ['users', 'give', 'available'],
      ['users', 'give', 'booked'],
      ['users', 'give', 'delivered'],
      ['woeid', nil, nil],
      ['woeid', 'want', nil],
      ['woeid', 'give', nil],
      ['woeid', 'give', 'available'],
      ['woeid', 'give', 'booked'],
      ['woeid', 'give', 'delivered']
    ].include?([controller, type, status])
    # rubocop:enable Style/WordArray
  end
end

Check for controller too in AdConstraint
Check for controller too in AdConstraint
