import Ember from 'ember'
import PagedRemoteArray from 'ember-cli-dunlop/utils/paged-remote-array'
export filters = Ember.Object.create
  workflow_action_definition_id_in: []
  workflow_action_definition_organization_id_eq: ''
  project_instance_group_workflow_group_id: ''
  state_in: []
  target_date_gteq: null
  target_date_lteq: null
  s: 'target_date asc'

export default Ember.Route.extend
  modelName: 'panda/project-instance-action'
  queryParams:
    state:           {refreshModel: true}
    organization_id: {refreshModel: true}
    page:            {refreshModel: true}
    perPage:         {refreshModel: true}
  setupController: (controller, model) ->
    controller.set 'filters', filters
    controller.set 'project', @modelFor('project.show')
    @_super arguments...

  model: (params) ->
    project = @modelFor 'project.show'
    filters.set('project_id', project.id)
    filters.set('state_in', params.state.split(',')) if params.state
    filters.set('workflow_action_definition_organization_id_eq', params.organization_id) if params.organization_id
    PagedRemoteArray.create
      modelName: @modelName
      store:       @store
      filters: filters
      page:        params.page || 1
      perPage:     params.perPage || 30
      otherParams:
        include: 'action-list'
