attr = DS.attr
App.List = DS.Model.extend
  needs_help: attr('boolean', defaultValue: false)
  needs_payment: attr('boolean', defaultValue: false)
  user_requests_closing: attr('boolean', defaultValue: false)
  state: attr('string')
  price: attr('number')
  closed_at: attr('date')
  extended_version: attr('boolean')
  supplier_orders_in_process_count: attr('number')
  supplier_orders_placed_count: attr('number')

  orders: DS.hasMany('order', async: true)
  supplier: DS.belongsTo('supplier', async: false)
  table: DS.belongsTo('table', async: true)
  join_requests: DS.hasMany('join_request', async: false)
  users: DS.hasMany('user', async: false)

  is_extended_version: ->
    @get('extended_version')
  relevant_orders: Ember.computed 'orders.@each.state', -> @get('orders').rejectBy('state', 'cancelled')
  sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.@each.isLoaded')
  total: (->
    @get('relevant_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
  ).property('relevant_orders.@each.total')
  active: Ember.computed.equal 'state', 'active'

  #showTotal: (->
  #  if @get('orders.length') && @get('orders.length') > 1 then true else false
  #).property('orders.length')
  showTotal: Ember.computed.gt 'relevant_orders.length', 1
