<commit_before>module Claims::Cloner
  extend ActiveSupport::Concern

  included do |klass|
    klass.amoeba do
      enable
      nullify :last_submitted_at
      nullify :original_submission_date
      nullify :uuid
      exclude_association :messages
      exclude_association :case_worker_claims
      exclude_association :case_workers
      exclude_association :claim_state_transitions
      exclude_association :versions
      exclude_association :fees
      exclude_association :expenses
      clone [:fees, :documents, :defendants, :expenses]
    end

    Fee.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:dates_attended]
      end
    end

    Defendant.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:representation_orders]
      end
    end

    Expense.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:dates_attended]
      end
    end

    RepresentationOrder.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end

    Document.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end

    DateAttended.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end
  end

  def clone_rejected_to_new_draft
    raise 'Can only clone claims in state "rejected"' unless rejected?

    draft = amoeba_dup
    draft.state = 'draft'
    draft.save!
    draft
  end
end<commit_msg>Fix cloning issues around fees and expenses<commit_after>module Claims::Cloner
  extend ActiveSupport::Concern

  included do |klass|
    klass.amoeba do
      enable
      nullify :last_submitted_at
      nullify :original_submission_date
      nullify :uuid
      exclude_association :messages
      exclude_association :case_worker_claims
      exclude_association :case_workers
      exclude_association :claim_state_transitions
      exclude_association :versions
      exclude_association :basic_fees
      exclude_association :fixed_fees
      exclude_association :misc_fees
      clone [:fees, :documents, :defendants, :expenses]
    end

    Fee.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:dates_attended]
      end
    end

    Defendant.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:representation_orders]
      end
    end

    Expense.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
        clone [:dates_attended]
      end
    end

    RepresentationOrder.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end

    Document.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end

    DateAttended.class_eval do |klass|
      klass.amoeba do
        enable
        nullify :uuid
      end
    end
  end

  def clone_rejected_to_new_draft
    raise 'Can only clone claims in state "rejected"' unless rejected?

    draft = amoeba_dup
    draft.state = 'draft'
    draft.save!

    draft
  end
end
{'fraction_non_alphanumeric': 0.0504070131496556, 'fraction_numerical': 0.0, 'mean_word_length': 2.1571146245059287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2982851', 'n_tokens_mistral': 989, 'n_tokens_neox': 957, 'n_words': 253}