# frozen_string_literal: true

module EE
  module Gitlab
    module BackgroundMigration
      module RemoveUndefinedVulnerabilityConfidenceLevel
        extend ::Gitlab::Utils::Override

        class Vulnerability < ActiveRecord::Base
          include ::EachBatch

          self.table_name = 'vulnerabilities'

          CONFIDENCE_LEVELS = {
            undefined: 0,
            unknown: 2
          }.with_indifferent_access.freeze

          enum confidence: CONFIDENCE_LEVELS

          def self.undefined_confidence
            where(confidence: Vulnerability.confidences[:undefined])
          end
        end

        override :perform
        def perform(start_id, stop_id)
          Vulnerability.undefined_confidence
                    .where(id: start_id..stop_id)
                    .update_all(confidence: Vulnerability.confidences[:unknown])
        end
      end
    end
  end
end
