attr = DS.attr
App.ProductCategory = DS.Model.extend Ember.Validations.Mixin,
  name: attr('string')
  active_on_sunday: attr('boolean', defaultValue: true)
  active_on_monday: attr('boolean', defaultValue: true)
  active_on_tuesday: attr('boolean', defaultValue: true)
  active_on_wednesday: attr('boolean', defaultValue: true)
  active_on_thursday: attr('boolean', defaultValue: true)
  active_on_friday: attr('boolean', defaultValue: true)
  active_on_saturday: attr('boolean', defaultValue: true)
  full_day: attr 'boolean', defaultValue: true
  start_from: attr('number')
  end_on: attr('number')
  position: attr('number')

  products: DS.hasMany('product', async: false)
  supplier: DS.belongsTo 'supplier', async: false

  sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position')

  availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', ->
    active_days = $days.filter (day)=>@get("active_on_#{day}")
    result = ""
    if active_days.length < 7
      result += "<span class=\"day-names\">#{active_days.map((day) -> tspan("date.day_name.#{day}")).join(", ")}</span> "
    unless @get('full_day')
      result += "<span class=\"time-range\">#{day_minutes_to_time @get('start_from')} - #{day_minutes_to_time @get('end_on')}</span>"
    result.htmlSafe()

  validations:
    name: {presence: true}
