module Dunlop::WorkflowInstanceCollection
  extend ActiveSupport::Concern

  def categorize_as(type_indication)
    raise "Can only categorize uncategorized instances" unless uncategorized?
    raise "#{type_indication} is not a configured scenario" unless WorkflowInstance.scenario_names.include?(type_indication)
    WorkflowInstance.where(id: ids).update_all(type: "WorkflowInstance::#{type_indication.classify}")
    WorkflowInstance.where(id: ids).find_each do |record|
      record.setup_subprocesses
      record.is_categorized
    end
  end

  def uncategorize!
    each(&:uncategorize!)
  end
end
