<commit_before>module Velocify
  class Lead
    include Model

    attr :fields
    attr_accessor :campaign_id, :agent_id, :status_id

    def initialize body: {}
      @body = body
    end

    def add_field id:, value:
      @fields = [] if @fields.nil?
      @fields << { id: id, value: value }
    end

    def campaign_id?; !@campaign_id.nil?; end

    def agent_id?; !@agent_id.nil?; end

    def status_id?; !@status_id.nil?; end

    class << self
      # Adds a lead or leads
      #
      # @param leads [String] The string representation of the XML document
      #                       containing the new leads
      #
      def add leads:, destruct: false, return_array: false
        verify_credentials!

        request do
          destruct_response? destruct
          operation :add_leads
          authenticate? true
          xml AddLeadsPayload.new(leads)
          transform do |resp|
            if return_array
              arrayify resp[:leads][:lead]
            else
              resp
            end
          end
        end
      end
      
      # Retrieves all leads
      #
      # @param from [String] The start date
      # @param to [String] The end date
      # @return [Hash] The leads between the `from:` and `to:` dates
      #
      def find_all from:, to:, destruct: false, return_array: false
        verify_credentials!

        request do
          destruct_response? destruct
          operation :get_leads
          message from: from, to: to
          authenticate? true
          transform do |resp|
            if return_array<commit_msg>Fixes return_array bug when adding leads<commit_after>module Velocify
  class Lead
    include Model

    attr :fields
    attr_accessor :campaign_id, :agent_id, :status_id

    def initialize body: {}
      @body = body
    end

    def add_field id:, value:
      @fields = [] if @fields.nil?
      @fields << { id: id, value: value }
    end

    def campaign_id?; !@campaign_id.nil?; end

    def agent_id?; !@agent_id.nil?; end

    def status_id?; !@status_id.nil?; end

    class << self
      # Adds a lead or leads
      #
      # @param leads [String] The string representation of the XML document
      #                       containing the new leads
      #
      def add leads:, destruct: false, return_array: false
        verify_credentials!

        request do
          destruct_response? destruct
          operation :add_leads
          authenticate? true
          xml AddLeadsPayload.new(leads)
          transform do |resp|
            if return_array
              arrayify resp[:response][:additions][:lead]
            else
              resp
            end
          end
        end
      end
      
      # Retrieves all leads
      #
      # @param from [String] The start date
      # @param to [String] The end date
      # @return [Hash] The leads between the `from:` and `to:` dates
      #
      def find_all from:, to:, destruct: false, return_array: false
        verify_credentials!

        request do
          destruct_response? destruct
          operation :get_leads
          message from: from, to: to
          authenticate? true
          transform do |resp|
            if return_array
{'fraction_non_alphanumeric': 0.07537220843672457, 'fraction_numerical': 0.0, 'mean_word_length': 1.7564102564102564, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5284284', 'n_tokens_mistral': 908, 'n_tokens_neox': 889, 'n_words': 298}