class InformationStandard < ActiveRecord::Base
  
  attr_accessible :information_standard_frame_id, :name, :acronym, :priority

  # Validations
  validates :name, :information_standard_frame_id, :acronym, :presence => true

  # Associations
  has_many :information_standard_infos, dependent: :destroy
  has_many :information_standard_categories, through: :information_standard_infos
  belongs_to :information_standard_frame
  has_many :information_ranking_histories, dependent: :destroy
  has_many :documents
  has_many :document_categories
  has_many :institution_information_standards_setting
  has_many :information_standard_criteria, dependent: :destroy
  accepts_nested_attributes_for :information_standard_criteria, reject_if: :all_blank, allow_destroy: true

  # FriendlyId
  extend FriendlyId
  friendly_id :name, :use => [:slugged, :history]
  
  enumerated_attribute :kind, %w(ordinary executive) do
    label ordinary: I18n.t('enum.information_standard.kind.ordinary')
    label executive: I18n.t('enum.information_standard.kind.executive')
  end

  def is_dynamical?
    Config[:dynamical_information_standards].values.include?(self.id)
  end
end
