class CourseParticipant < ActiveRecord::Base
  attr_accessible :first_name, :last_name, :gender, :institution_type, :state_id, :city_id, :charge, :activities, :educational_level
  attr_accessible :specialty, :phone, :institutional_phone, :email, :email_confirmation, :institutional_email, :comment, :code, :institution

  belongs_to :state
  belongs_to :city

  # Acts as TextCaptcha
  acts_as_textcaptcha

  validates :first_name, :last_name, :gender, :institution, :city_id, :state_id, :phone, :email, :comment, presence: true
  validates :email, confirmation: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }

  enumerated_attribute :gender, %w(^F M) do
    label F: I18n.t('enum.course_participant.gender.female')
    label M: I18n.t('enum.course_participant.gender.male')
  end

  enumerated_attribute :institution_type, %w(^private public) do
    label private: I18n.t('enum.course_participant.institution_type.private')
    label public: I18n.t('enum.course_participant.institution_type.public')
  end

  enumerated_attribute :educational_level, %w(^none primary secondary highschool technical university postgrade doctorate) do
    label none: I18n.t('enum.course_participant.educational_level.none')
    label primary: I18n.t('enum.course_participant.educational_level.primary')
    label secondary: I18n.t('enum.course_participant.educational_level.secondary')
    label highschool: I18n.t('enum.course_participant.educational_level.highschool')
    label technical: I18n.t('enum.course_participant.educational_level.technical')
    label university: I18n.t('enum.course_participant.educational_level.university')
    label postgrade: I18n.t('enum.course_participant.educational_level.postgrade')
    label doctorate: I18n.t('enum.course_participant.educational_level.doctorate')
  end

  def deliver_register_participant_email
    UserMailer.register_participant_email(self).deliver
  end
end
