<commit_before># frozen_string_literal: true

require 'deprecation'

module Dor
  module Workflow
    class Client
      # Makes requests relating to a workflow
      class WorkflowRoutes
        extend Deprecation

        def initialize(requestor:)
          @requestor = requestor
        end

        # This method is deprecated and calls create_workflow_by_name.
        #
        # @param [String] repo Ignored
        # @param [String] druid The id of the object
        # @param [String] workflow_name The name of the workflow you want to create
        # @param [String] wf_xml Ignored
        # @param [Hash] opts optional params
        # @option opts [Boolean] :create_ds if true, a workflow datastream will be created in Fedora.  Set to false if you do not want a datastream to be created
        #   If you do not pass in an <b>opts</b> Hash, then :create_ds is set to true by default
        # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml.  Defaults to a value of 'default'
        # @return [Boolean] always true
        #
        def create_workflow(_repo, druid, workflow_name, _wf_xml, opts = { create_ds: true })
          create_workflow_by_name(druid, workflow_name, opts)
        end
        deprecation_deprecate create_workflow: 'use create_workflow_by_name instead'

        # Creates a workflow for a given object in the repository.  If this particular workflow for this objects exists,
        # it will replace the old workflow.  You have the option of creating a datastream or not.
        # Returns true on success.  Caller must handle any exceptions.
        #
        # @param [String] repo The repository the object resides in.  The service recoginzes "dor" and "sdr" at the moment
        # @param [String] druid The id of the object
        # @param [String] workflow_name The name of the workflow you want to create. This must correspond with a workflow
        # name that is known by the workflow service.
        # @param [Hash] opts optional params
        # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml.  Defaults to a value of 'default'
        # @return [Boolean] always true
        #
        def create_workflow_by_name(druid, workflow_name, opts = { create_ds: true })
          requestor.request "objects/#{druid}/workflows/#{workflow_name}", 'post', '',
                            content_type: 'application/xml',
                            params: { 'lane-id' => opts.fetch(:lane_id, 'default') }
          true
        end

        # Updates the status of one step in a workflow.
        # Returns true on success.  Caller must handle any exceptions
        #
        # @param [String] repo The repository the object resides in.  The service recoginzes "dor" and "sdr" at the moment
        # @param [String] druid The id of the object
        # @param [String] workflow The name of the workflow
        # @param [String] process The name of the process step
        # @param [String] status The status that you want to set -- using one of the values in VALID_STATUS
        # @param [Hash] opts optional values for the workflow step
        # @option opts [Float] :elapsed The number of seconds it took to complete this step. Can have a decimal.  Is set to 0 if not passed in.
        # @option opts [String] :lifecycle Bookeeping label for this particular workflow step.  Examples are: 'registered', 'shelved'<commit_msg>Remove some further create_ds code<commit_after># frozen_string_literal: true

require 'deprecation'

module Dor
  module Workflow
    class Client
      # Makes requests relating to a workflow
      class WorkflowRoutes
        extend Deprecation

        def initialize(requestor:)
          @requestor = requestor
        end

        # This method is deprecated and calls create_workflow_by_name.
        #
        # @param [String] repo Ignored
        # @param [String] druid The id of the object
        # @param [String] workflow_name The name of the workflow you want to create
        # @param [String] wf_xml Ignored
        # @param [Hash] opts optional params
        # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml.  Defaults to a value of 'default'
        # @return [Boolean] always true
        #
        def create_workflow(_repo, druid, workflow_name, _wf_xml, opts = {})
          create_workflow_by_name(druid, workflow_name, opts)
        end
        deprecation_deprecate create_workflow: 'use create_workflow_by_name instead'

        # Creates a workflow for a given object in the repository.  If this particular workflow for this objects exists,
        # it will replace the old workflow.  You have the option of creating a datastream or not.
        # Returns true on success.  Caller must handle any exceptions.
        #
        # @param [String] repo The repository the object resides in.  The service recoginzes "dor" and "sdr" at the moment
        # @param [String] druid The id of the object
        # @param [String] workflow_name The name of the workflow you want to create. This must correspond with a workflow
        # name that is known by the workflow service.
        # @param [Hash] opts optional params
        # @option opts [String] :lane_id adds laneId attribute to all process elements in the wf_xml workflow xml.  Defaults to a value of 'default'
        # @return [Boolean] always true
        #
        def create_workflow_by_name(druid, workflow_name, opts = {})
          requestor.request "objects/#{druid}/workflows/#{workflow_name}", 'post', '',
                            content_type: 'application/xml',
                            params: { 'lane-id' => opts.fetch(:lane_id, 'default') }
          true
        end

        # Updates the status of one step in a workflow.
        # Returns true on success.  Caller must handle any exceptions
        #
        # @param [String] repo The repository the object resides in.  The service recoginzes "dor" and "sdr" at the moment
        # @param [String] druid The id of the object
        # @param [String] workflow The name of the workflow
        # @param [String] process The name of the process step
        # @param [String] status The status that you want to set -- using one of the values in VALID_STATUS
        # @param [Hash] opts optional values for the workflow step
        # @option opts [Float] :elapsed The number of seconds it took to complete this step. Can have a decimal.  Is set to 0 if not passed in.
        # @option opts [String] :lifecycle Bookeeping label for this particular workflow step.  Examples are: 'registered', 'shelved'
{'fraction_non_alphanumeric': 0.06625967837998809, 'fraction_numerical': 0.0002977963073257892, 'mean_word_length': 2.5615058324496287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5888958', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1759, 'n_words': 803}