<commit_before>class ClaimCsvPresenter < BasePresenter

  presents :claim

  def present!
    yield parsed_journeys
  end

  def journeys
    sorted_and_filtered_state_transitions.slice_after {|transition| completed_states.include?(transition.to) }
  end

  def sorted_and_filtered_state_transitions
    claim_state_transitions.sort.reject { |transition| (transition.to == 'draft' || transition.to == 'archived_pending_delete') }
  end

  def parsed_journeys
    journeys.map do |journey|
      @journey = clean_deallocations(journey)
      Settings.claim_csv_headers.map { |method_call| send(method_call) }
    end
  end

  def clean_deallocations(journey)
    deallocation = journey.reverse.find { |transition| transition.event == 'deallocate' }
    if deallocation
      journey.reject! { |transition| transition.event == 'allocate' && transition.created_at < deallocation.created_at }
      journey.reject! { |transition| transition.event == 'deallocate' }
    end
    journey
  end

  def case_worker
    if claim.allocated?
      claim.case_workers.first.name
    else
      transition = claim.last_decision_transition
      transition&.author_name
    end

  end

  def claim_state
    if state == 'archived_pending_delete'
      claim_state_transitions.sort.last.from
    else
      state
    end
  end

  def organisation
    provider.name
  end

  def case_type_name
    case_type.name
  end

  def scheme
    if type == 'Claim::AdvocateClaim'
      'AGFS'
    elsif %w( Claim::LitigatorClaim Claim::InterimClaim Claim::TransferClaim ).include? type
      'LGFS'
    else
      'Unknown'
    end
  end

  def claim_total
    total_including_vat.to_s
  end

  def submission_type
    @journey.first.to == 'submitted' ? 'new' : @journey.first.to
  end<commit_msg>Allow nil case type on transfer claims and handle in management info report<commit_after>class ClaimCsvPresenter < BasePresenter

  presents :claim

  def present!
    yield parsed_journeys
  end

  def journeys
    sorted_and_filtered_state_transitions.slice_after {|transition| completed_states.include?(transition.to) }
  end

  def sorted_and_filtered_state_transitions
    claim_state_transitions.sort.reject { |transition| (transition.to == 'draft' || transition.to == 'archived_pending_delete') }
  end

  def parsed_journeys
    journeys.map do |journey|
      @journey = clean_deallocations(journey)
      Settings.claim_csv_headers.map { |method_call| send(method_call) }
    end
  end

  def clean_deallocations(journey)
    deallocation = journey.reverse.find { |transition| transition.event == 'deallocate' }
    if deallocation
      journey.reject! { |transition| transition.event == 'allocate' && transition.created_at < deallocation.created_at }
      journey.reject! { |transition| transition.event == 'deallocate' }
    end
    journey
  end

  def case_worker
    if claim.allocated?
      claim.case_workers.first.name
    else
      transition = claim.last_decision_transition
      transition&.author_name
    end

  end

  def claim_state
    if state == 'archived_pending_delete'
      claim_state_transitions.sort.last.from
    else
      state
    end
  end

  def organisation
    provider.name
  end

  def case_type_name
    case_type&.name || 'n/a'
  end

  def scheme
    if type == 'Claim::AdvocateClaim'
      'AGFS'
    elsif %w( Claim::LitigatorClaim Claim::InterimClaim Claim::TransferClaim ).include? type
      'LGFS'
    else
      'Unknown'
    end
  end

  def claim_total
    total_including_vat.to_s
  end

  def submission_type
    @journey.first.to == 'submitted' ? 'new' : @journey.first.to
  end
{'fraction_non_alphanumeric': 0.0835639180962922, 'fraction_numerical': 0.0, 'mean_word_length': 3.344951923076923, 'pattern_counts': {'":': 0, '<': 7, '<?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': '233031', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1123, 'n_words': 246}