# frozen_string_literal: true

class VulnerabilityBulletinStatus < ApplicationRecord

  validates :name, uniqueness: true
  validates :name, length: { minimum: 1, maximum: 200 }
  validates :organization_id, numericality: { only_integer: true, allow_blank: true }
  validates :rank, numericality: { only_integer: true, allow_blank: true }

  belongs_to :organization, optional: true
  has_many :vulnerability_bulletins, dependent: :restrict_with_error

  def self.allowed_statuses(current_user)
    where(organization_id: current_user.organization_id)
      .or(VulnerabilityBulletinStatus.where('organization_id IS NULL'))
  end
end
