class Page < ActiveRecord::Base
  
  attr_accessible :active, :content, :name, :priority, :portal, :page_id, :link, :restricted
  
  # Associations
  has_many :pages, order: :priority
  belongs_to :page
  has_many :attachments, as: :attachable
  has_many :attachment_categories, through: :attachments, uniq: true, order: :name
  
  # Validations
  validates :name, :presence => true
  validates :priority, :numericality => { :only_integer => true }
  
  # FriendlyId
  extend FriendlyId
  friendly_id :name, :use => [:slugged, :history]
  
  # Enumerated attributes for portal field
  enum_attr :portal, %w(infoutil www consulta) do
    label :infoutil => I18n.t('enum.page.portal.infoutil')
    label :www => I18n.t('enum.page.portal.www')
    label :consulta => I18n.t('enum.page.portal.consulta')
  end
  
  # Will paginate uses this method
  # to know how many rows to show
  #
  def self.per_page
    50
  end
end
