# frozen_string_literal: true

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

        class Occurrence < ActiveRecord::Base
          include ::EachBatch

          self.table_name = 'vulnerability_occurrences'

          REPORT_TYPES = {
            container_scanning: 2
          }.freeze

          CONFIDENCE_LEVELS = {
            unknown: 2,
            medium: 5
          }.freeze

          enum confidences: CONFIDENCE_LEVELS
          enum report_type: REPORT_TYPES

          def self.container_scanning_reports_with_medium_confidence
            where(report_type: self.report_types[:container_scanning], confidence: self.confidences[:medium])
          end
        end

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