-class Scheduler.Ticket extends Backbone.Model
+class Scheduler.Ticket extends @Ticket
   urlRoot: '/scheduler/tickets'
   
-  tasks: -> @_tasks ?= new Scheduler.Tasks(@get('tasks'))
-  estimatedEffort: ->
-    effort = @tasks().reduce ((sum, task)-> sum + +task.get('effort')), 0
-    if effort == 0 then null else effort
   estimated: -> @tasks().every (task)-> +task.get('effort') > 0
   waitingForDiscussion: -> @get('unableToSetEstimatedEffort') or @get('unableToSetPriority')
   
-  severity: ->
-    seriousness = @get('seriousness')
-    likelihood = @get('likelihood')
-    clumsiness = @get('clumsiness')
-    return false unless seriousness && likelihood && clumsiness
-    (0.6 * seriousness + 0.3 * likelihood + 0.1 * clumsiness).toFixed(1)
-  
   value: ->
     0
+  
+  tasks: -> @_tasks ?= new Scheduler.Tasks(@get('tasks'))
   
   addTask: (attributes)->
     xhr = $.post "/scheduler/tickets/#{@id}/tasks", attributes

  waitingForDiscussion: -> @scoped (ticket)-> ticket.waitingForDiscussion()
  postponed: -> @scoped (ticket)-> !!ticket.get('postponed')
  unpostponed: -> @scoped (ticket)-> !ticket.get('postponed')

  orderBy: (attribute, ascOrDesc)->
    tickets = @sortBy(@sorterFor(attribute))
    tickets = tickets.reverse() if ascOrDesc == 'desc'
    new Scheduler.Tickets(tickets)
  
  sorterFor: (attribute)->
    switch attribute
      when 'sequence'     then (ticket)-> +ticket.get('sequence')
      when 'effort'       then (ticket)-> ticket.estimatedEffort()
      when 'severity'     then (ticket)-> ticket.severity()
      when 'seriousness'  then (ticket)-> +ticket.get('seriousness')
      when 'likelihood'   then (ticket)-> +ticket.get('likelihood')
      when 'clumsiness'   then (ticket)-> +ticket.get('clumsiness')
      when 'summary'      then (ticket)-> ticket.get('summary').toLowerCase().replace(/^\W/, '')
      when 'openedAt'     then (ticket)-> ticket.get('openedAt')
      else throw "sorterFor doesn't know how to sort #{attribute}!"

  scoped: (filter)-> new Scheduler.Tickets(@select(filter))

    String.fromCharCode(bytes)
  
  parse: (ticket)->
    ticket = super(ticket)
    if ticket.extendedAttributes
      ticket.sequence = +ticket.extendedAttributes['sequence']
      ticket.sequence = null if !ticket.sequence
