 
 class Course
 
-  constructor: (attributes) ->
+  constructor: (@user, attributes) ->
     @channel = new EventEmitter2
     @set(attributes)
-    api.channel.on "course.#{@ecosystem_book_uuid}.registration.complete", ({data}) =>
-      _.extend(this, data)
+    _.bindAll(@, '_onRegistered', '_onConfirmed')
 
-    api.channel.on "course.#{@ecosystem_book_uuid}.registration.failure", ({data}) =>
-      _.extend(@, data)
-      @channel.emit('change')
+
+  isPending: ->
+    @status is "pending"
+
+  description: ->
+    if @isIncomplete() # still fetching
+      ""
+    else if @isPending() # we originated from a join request
+      "#{@to.course.name} #{@to.period.name} period"
+    else
+      "#{@name} #{_.first(@periods).name} period"
+
+  isIncomplete: -> not (@name or @to)
 
   set: (attributes) ->
     _.extend(@, attributes)


  register: (inviteCode) ->
    @errors = []
    api.channel.emit("course.#{@ecosystem_book_uuid}.send.registration", data: {
      book_cnx_id: @ecosystem_book_uuid, enrollment_code: inviteCode
    })



module.exports = Course

React = require 'react'
EventEmitter2 = require 'eventemitter2'

api  = require '../api'

ERROR_MAP = {
  invalid_enrollment_code: 'The enrollment code is invalid'
