# frozen_string_literal: true

module EE
  module VulnerabilityFindingSignatureHelpers
    extend ActiveSupport::Concern

    # If the location object describes a physical location within a file
    # (filename + line numbers), the 'location' algorithm_type should be used
    #
    # If the location object describes arbitrary data, then the 'hash'
    # algorithm_type should be used.
    PRIORITIES = {
      scope_offset: 3,
      location: 2,
      hash: 1
    }.with_indifferent_access.freeze

    class_methods do
      def priority(algorithm_type)
        raise ArgumentError, "No priority for #{algorithm_type.inspect}" unless PRIORITIES.key?(algorithm_type)

        PRIORITIES[algorithm_type]
      end
    end

    def priority
      self.class.priority(algorithm_type)
    end
  end
end
