module Gitlab
  module Vulnerabilities
    class StandardVulnerability < BaseVulnerability
      def title
        @data[:name]
      end

      # Passthrough properties
      %i[
        severity
        confidence
        solution
      ].each do |method_name|
        define_method(method_name) do
          @data[method_name]
        end
      end

      def description
        @data[:description].presence || @data[:name]
      end

      def identifiers
        return [] unless @data[:identifiers].present?

        ids = []
        @data[:identifiers].each do |identifier|
          # Only show known identifiers
          case identifier[:name]
          when 'CVE'
            ids << {
              value: identifier[:value],
              link: cve_link(identifier[:value])
            }
          when 'CWE'
            ids << {
              value: "CWE-#{identifier[:value]}",
              link: cwe_link(identifier[:value])
            }
          end
        end

        ids
      end
    end
  end
end
