# frozen_string_literal: true

module VulnerabilityExports
  module Exporters
    class CsvService
      MAPPING = {
        'Group Name' => 'group_name',
        'Project Name' => 'project_name',
        'Scanner Type' => 'report_type',
        'Scanner Name' => 'finding_scanner_name',
        'Status' => 'state',
        'Vulnerability' => 'title',
        'Details' => 'finding_description',
        'Additional Info' => 'finding_message',
        'Severity' => 'severity',
        'CVE' => 'finding_cve'
      }.freeze

      attr_reader :vulnerabilities

      def initialize(vulnerabilities)
        @vulnerabilities = vulnerabilities
      end

      def generate(&block)
        csv_builder.render(&block)
      end

      private

      def csv_builder
        @csv_builder ||= CsvBuilder.new(vulnerabilities, MAPPING)
      end
    end
  end
end
