# represenst the type of lesson package
module JamRuby
  class TestDrivePackageTeacher < ActiveRecord::Base

    @@log = Logging.logger[TestDrivePackageTeacher]

    attr_writer :short_bio_temp
    attr_accessible :user_id, :test_drive_package_id, :short_bio, :short_bio_temp, as: :admin

    belongs_to :test_drive_package, class_name: "JamRuby::TestDrivePackage"
    belongs_to :user, class_name: "JamRuby::User"

    validates :user, presence: true
    validates :test_drive_package, presence: true

    after_save :after_save

    # silly pass through for activeadmin.  We pass short_bio set here on to teacher
    def after_save
      if user && user.teacher
          if @another_bio.present?
            user.teacher.short_bio = @another_bio
            user.teacher.save!
          end
      end
    end

    def short_bio_temp=(short_bio)
      self.updated_at = Time.now
      self.short_bio = short_bio
      @another_bio = short_bio
    end
    def short_bio_temp
      if user && user.teacher
        user.teacher.short_bio
      end
    end
  end
end

