FactoryBot.define do
  factory :workflow_instance do
    after(:build){|instance| instance.setup_workflow_steps }
    state "unplanned" # default for Vula

    trait :uncategorized do
        state 'uncategorized'
    end

    trait :unplanned do
      state 'unplanned'
    end

    trait :planned do
      state 'planned'
    end

    trait :active do
      state 'active'
      after :build do |instance|
        instance.workflow_steps.first.state = 'processing'
      end
    end

    trait :overdue do
      state 'overdue'
      after :build do |instance|
        instance.owner_initialization.plan_date = 1.year.ago
        instance.contractor_initialization.state = 'overdue'
      end
    end

    trait :all_completed do
      state 'all_completed'
      after :build do |instance|
        instance.workflow_steps.each{|workflow_step| workflow_step.state = 'completed' }
      end
    end

    trait :any_rejected do
      state 'any_rejected'
      after :build do |instance|
        instance.workflow_steps.first.state = 'rejected'
      end
    end

    trait :with_values do

    end
  end

  factory :workflow_instance_for_workflow_step_test, class: 'WorkflowInstance::Scenario1', parent: :workflow_instance_scenario1

  factory 'workflow_instance/scenario1', aliases: [:workflow_instance_scenario1], class: 'WorkflowInstance::Scenario1', parent: :workflow_instance
  factory 'workflow_instance/scenario2', aliases: [:workflow_instance_scenario2], class: 'WorkflowInstance::Scenario2', parent: :workflow_instance
end

