import DS from 'ember-data'
import add_business_day_computations from 'ember-panda/utils/business-day-computations'

Model =
  identifier:              DS.attr('string')
  name:                    DS.attr('string')
  position:                DS.attr('number', defaultValue: 0)
  offset_type:             DS.attr('string', defaultValue: 'none') # none, connected_finish, connected_start

  project:                     DS.belongsTo('panda/project')
  constraints:                 DS.hasMany('panda/workflow-group-constraint', inverse: 'workflow_group')
  tracker_groups:              DS.hasMany('panda/tracker-group', serialize: 'ids')
  workflow_action_definitions: DS.hasMany('panda/workflow_action_definition')
  project_scenarios:           DS.hasMany('panda/project-scenario')

  offset_base:                 DS.belongsTo('panda/workflow-group', inverse: 'offset_dependents')
  offset_dependents:           DS.hasMany('panda/workflow-group', inverse: null) # do not give with api, will clear inverse if not given

  workflowActionDefinitionSort: ['position:asc']
  sorted_workflow_action_definitions: Ember.computed.sort('workflow_action_definitions', 'workflowActionDefinitionSort')
add_business_day_computations Model, 'offset', add_attributes: true
add_business_day_computations Model, 'duration', add_attributes: true
add_business_day_computations Model, 'batch_element_threshold', add_attributes: true #, default_unit: 'businessday'
export default DS.Model.extend(Model)
