attr = DS.attr
App.List = DS.Model.extend
  orders: DS.hasMany('order')
  needs_help: attr('boolean')
  needs_payment: attr('boolean')
  user_requests_closing: attr('boolean')
  supplier_name: attr('string')
  state: attr('string')
  price: attr('number')
  closed_at: DS.attr('date')
  extended_version: attr('boolean')
  supplier_orders_in_process_count: attr('number')
  supplier_orders_placed_count: attr('number')

  supplier: DS.belongsTo('supplier')
  table: DS.belongsTo('table')
  join_requests: DS.hasMany('join_request')
  users: DS.hasMany('user')

  total: (->
    @get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
  ).property('orders.@each.total')

  is_extended_version: ->
    @get('extended_version')

  sorted_orders: (-> @get('orders').sortBy('created_at').reverseObjects()).property('orders.@each.isLoaded')
