module JamRuby
  class TeacherIntent < ActiveRecord::Base

    belongs_to :user, class_name: ::JamRuby::User
    belongs_to :teacher, class_name: ::JamRuby::Teacher

    validates :user, presence: true
    validates :teacher, presence: true
    validates :intent, presence: true

    def self.create(user, teacher, intent)
      teacher_intent = TeacherIntent.new
      teacher_intent.user = user
      teacher_intent.teacher = teacher
      teacher_intent.intent = intent
      teacher_intent.save
      teacher_intent
    end

    def self.recent_test_drive(user)
      TeacherIntent.where(intent: 'book-test-drive').where(user_id: user.id).where('created_at > ?', Date.today - 30).order('created_at DESC').first
    end
  end
end
