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

    @@log = Logging.logger[TestDrivePackage]

    attr_accessible :name, :description, :package_type, :test_drive_package_teachers_attributes, :test_drive_package_teachers, as: :admin

    has_many :test_drive_package_teachers, class_name: "JamRuby::TestDrivePackageTeacher"

    validates :name, presence: true, uniqueness: true
    validates :package_type, presence: true

    #validate :teacher_count


    def teacher_count
      if package_type != test_drive_package_teachers.length
        self.errors.add(:test_drive_package_teachers, "wrong number of teachers specified for the given package type #{package_type}")
      end
    end

    accepts_nested_attributes_for :test_drive_package_teachers, allow_destroy: true
  end
end

