# frozen_string_literal: true

class Cve < ActiveRecord::Base
  scope :with_reserved, -> { where("cve_data_meta->>'STATE' = 'RESERVED'") }
  scope :without_reserved, -> { where.not("cve_data_meta->>'STATE' = 'RESERVED'") }
  scope :with_rejected, -> { where("cve_data_meta->>'STATE' = 'REJECT'") }
  scope :without_rejected, -> { where.not("cve_data_meta->>'STATE' = 'REJECT'") }
  scope :with_public, -> { where("cve_data_meta->>'STATE' = 'PUBLIC'") }
  scope :without_public, -> { where.not("cve_data_meta->>'STATE' = 'PUBLIC'") }

  def self.find_by_id(id)
    find_by(cve_id: id)
  end

  def self.from_year(year)
    where('cve_id LIKE ?', "CVE-#{year}-%")
  end
end