class InstitutionOfficial < ActiveRecord::Base

  # Accessible attributes
  attr_accessible :curriculum, :description, :email, :job, :name, :phone, :institution_id, :active, :committee_id, :address

  # Non database attributes
  attr_accessible :picture

  # Associations
  belongs_to :institution
  belongs_to :committee

  # Validations
  validates :name, :email, :institution_id, presence: true
  validates :curriculum, :description, :job, :phone, :address, presence: true

  # scopes
  scope :active, where(active: true)

  # Paper trail, track changes
  has_paper_trail

  # Will paginate uses this method
  # to know how many rows to show
  #
  def self.per_page
    50
  end

  # Paperclip
  has_attached_file :picture,
    content_type: ['image/jpeg', 'image/jpg', 'image/png'],
    styles: { original: '260x260>' },
    default_style: :original

  def data_for_csv
    [
      name,
      description,
      job,
      phone,
      email,
      address,
      curriculum
    ]
  end

  def self.header_for_csv
    [:name, :description, :job, :phone, :email, :address, :curriculum]
  end

  def self.attributes_for_grid
    [
      :institution_id,
      :name,
      :description,
      :job,
      :phone,
      :email,
      :address,
      :curriculum,
      :active
    ]
  end
end
