<commit_before>
days_of_the_week = Calculators::MaternityPaternityCalculator::DAYS_OF_THE_WEEK

## QM1
date_question :baby_due_date_maternity? do
  from { 1.year.ago(Date.today) }
  to { 2.years.since(Date.today) }

  calculate :calculator do |response|
    Calculators::MaternityPaternityCalculator.new(response)
  end
  next_node :employment_contract?
end

## QM2
multiple_choice :employment_contract? do
  option :yes
  option :no

  save_input_as :has_employment_contract

  next_node :date_leave_starts?
end

## QM3
date_question :date_leave_starts? do
  from { 2.years.ago(Date.today) }
  to { 2.years.since(Date.today) }

  precalculate :leave_earliest_start_date do
    calculator.leave_earliest_start_date
  end

  calculate :leave_start_date do |response|
    ls_date = response
    raise SmartAnswer::InvalidResponse if ls_date < leave_earliest_start_date
    calculator.leave_start_date = ls_date
    calculator.leave_start_date
  end

  calculate :leave_end_date do
    calculator.leave_end_date
  end
  calculate :leave_earliest_start_date do
    calculator.leave_earliest_start_date
  end
  calculate :notice_of_leave_deadline do
    calculator.notice_of_leave_deadline
  end

  calculate :pay_start_date do
    calculator.pay_start_date
  end
  calculate :pay_end_date do
    calculator.pay_end_date
  end
  calculate :employment_start do
    calculator.employment_start
  end
  calculate :qualifying_week_start do
    calculator.qualifying_week.first
  end
  calculate :ssp_stop do
    calculator.ssp_stop
  end
  next_node :did_the_employee_work_for_you?
end

## QM4
multiple_choice :did_the_employee_work_for_you? do
  option :yes
  option :no
  calculate :not_entitled_to_pay_reason do |response|
    response == 'no' ? :not_worked_long_enough : nil
  end

  permitted_next_nodes = [
    :is_the_employee_on_your_payroll?,
    :maternity_leave_and_pay_result
  ]
  next_node(permitted: permitted_next_nodes) do |response|
    case response
    when 'yes'
      :is_the_employee_on_your_payroll?
    when 'no'
      :maternity_leave_and_pay_result
    end
  end
end

## QM5
multiple_choice :is_the_employee_on_your_payroll? do
  option :yes
  option :no

  calculate :not_entitled_to_pay_reason do |response|
    response == 'no' ? :must_be_on_payroll : nil
  end

  calculate :to_saturday do
    calculator.qualifying_week.last
  end

  calculate :to_saturday_formatted do
    calculator.format_date_day to_saturday
  end

  permitted_next_nodes = [
    :last_normal_payday?,
    :maternity_leave_and_pay_result
  ]
  next_node(permitted: permitted_next_nodes) do |response|
    case response
    when 'yes'
      :last_normal_payday? # NOTE: goes to shared questions
    when 'no'
      :maternity_leave_and_pay_result
    end
  end
end

## QM6
date_question :last_normal_payday? do
  from { 2.years.ago(Date.today) }
  to { 2.years.since(Date.today) }

  calculate :last_payday do |response|
    calculator.last_payday = response
    raise SmartAnswer::InvalidResponse if calculator.last_payday > to_saturday
    calculator.last_payday
  end
  next_node :payday_eight_weeks?
end

## QM7
date_question :payday_eight_weeks? do
  from { 2.year.ago(Date.today) }
  to { 2.years.since(Date.today) }

  precalculate :payday_offset do
    calculator.payday_offset
  end

  precalculate :payday_offset_formatted do
    calculator.format_date_day payday_offset
  end

  calculate :last_payday_eight_weeks do |response|
    payday = response + 1.day
    raise SmartAnswer::InvalidResponse if payday > payday_offset
    calculator.pre_offset_payday = payday
    payday
  end

  calculate :relevant_period do
    calculator.formatted_relevant_period
  end

  next_node :pay_frequency?
end

## QM8
multiple_choice :pay_frequency? do
  save_input_as :pay_pattern
  option :weekly
  option :every_2_weeks
  option :every_4_weeks
  option :monthly

  next_node(:earnings_for_pay_period?)
end

## QM9 Maternity only onwards
money_question :earnings_for_pay_period? do
  calculate :calculator do |response|
    calculator.calculate_average_weekly_pay(pay_pattern, response)
    calculator
  end
  calculate :average_weekly_earnings do
    calculator.average_weekly_earnings
  end
  next_node :how_do_you_want_the_smp_calculated?
end

## QM10
multiple_choice :how_do_you_want_the_smp_calculated? do
  option :weekly_starting
  option :usual_paydates

  save_input_as :smp_calculation_method

  on_condition(responded_with("usual_paydates")) do
    next_node_if(:when_in_the_month_is_the_employee_paid?, variable_matches(:pay_pattern, "monthly"))
    next_node(:when_is_your_employees_next_pay_day?)
  end
  next_node(:maternity_leave_and_pay_result)
end

## QM11
date_question :when_is_your_employees_next_pay_day? do
  calculate :next_pay_day do |response|
    calculator.pay_date = response
    calculator.pay_date
  end<commit_msg>Use next_node block in :how_do_you_want_the_smp_calculated?<commit_after>
days_of_the_week = Calculators::MaternityPaternityCalculator::DAYS_OF_THE_WEEK

## QM1
date_question :baby_due_date_maternity? do
  from { 1.year.ago(Date.today) }
  to { 2.years.since(Date.today) }

  calculate :calculator do |response|
    Calculators::MaternityPaternityCalculator.new(response)
  end
  next_node :employment_contract?
end

## QM2
multiple_choice :employment_contract? do
  option :yes
  option :no

  save_input_as :has_employment_contract

  next_node :date_leave_starts?
end

## QM3
date_question :date_leave_starts? do
  from { 2.years.ago(Date.today) }
  to { 2.years.since(Date.today) }

  precalculate :leave_earliest_start_date do
    calculator.leave_earliest_start_date
  end

  calculate :leave_start_date do |response|
    ls_date = response
    raise SmartAnswer::InvalidResponse if ls_date < leave_earliest_start_date
    calculator.leave_start_date = ls_date
    calculator.leave_start_date
  end

  calculate :leave_end_date do
    calculator.leave_end_date
  end
  calculate :leave_earliest_start_date do
    calculator.leave_earliest_start_date
  end
  calculate :notice_of_leave_deadline do
    calculator.notice_of_leave_deadline
  end

  calculate :pay_start_date do
    calculator.pay_start_date
  end
  calculate :pay_end_date do
    calculator.pay_end_date
  end
  calculate :employment_start do
    calculator.employment_start
  end
  calculate :qualifying_week_start do
    calculator.qualifying_week.first
  end
  calculate :ssp_stop do
    calculator.ssp_stop
  end
  next_node :did_the_employee_work_for_you?
end

## QM4
multiple_choice :did_the_employee_work_for_you? do
  option :yes
  option :no
  calculate :not_entitled_to_pay_reason do |response|
    response == 'no' ? :not_worked_long_enough : nil
  end

  permitted_next_nodes = [
    :is_the_employee_on_your_payroll?,
    :maternity_leave_and_pay_result
  ]
  next_node(permitted: permitted_next_nodes) do |response|
    case response
    when 'yes'
      :is_the_employee_on_your_payroll?
    when 'no'
      :maternity_leave_and_pay_result
    end
  end
end

## QM5
multiple_choice :is_the_employee_on_your_payroll? do
  option :yes
  option :no

  calculate :not_entitled_to_pay_reason do |response|
    response == 'no' ? :must_be_on_payroll : nil
  end

  calculate :to_saturday do
    calculator.qualifying_week.last
  end

  calculate :to_saturday_formatted do
    calculator.format_date_day to_saturday
  end

  permitted_next_nodes = [
    :last_normal_payday?,
    :maternity_leave_and_pay_result
  ]
  next_node(permitted: permitted_next_nodes) do |response|
    case response
    when 'yes'
      :last_normal_payday? # NOTE: goes to shared questions
    when 'no'
      :maternity_leave_and_pay_result
    end
  end
end

## QM6
date_question :last_normal_payday? do
  from { 2.years.ago(Date.today) }
  to { 2.years.since(Date.today) }

  calculate :last_payday do |response|
    calculator.last_payday = response
    raise SmartAnswer::InvalidResponse if calculator.last_payday > to_saturday
    calculator.last_payday
  end
  next_node :payday_eight_weeks?
end

## QM7
date_question :payday_eight_weeks? do
  from { 2.year.ago(Date.today) }
  to { 2.years.since(Date.today) }

  precalculate :payday_offset do
    calculator.payday_offset
  end

  precalculate :payday_offset_formatted do
    calculator.format_date_day payday_offset
  end

  calculate :last_payday_eight_weeks do |response|
    payday = response + 1.day
    raise SmartAnswer::InvalidResponse if payday > payday_offset
    calculator.pre_offset_payday = payday
    payday
  end

  calculate :relevant_period do
    calculator.formatted_relevant_period
  end

  next_node :pay_frequency?
end

## QM8
multiple_choice :pay_frequency? do
  save_input_as :pay_pattern
  option :weekly
  option :every_2_weeks
  option :every_4_weeks
  option :monthly

  next_node(:earnings_for_pay_period?)
end

## QM9 Maternity only onwards
money_question :earnings_for_pay_period? do
  calculate :calculator do |response|
    calculator.calculate_average_weekly_pay(pay_pattern, response)
    calculator
  end
  calculate :average_weekly_earnings do
    calculator.average_weekly_earnings
  end
  next_node :how_do_you_want_the_smp_calculated?
end

## QM10
multiple_choice :how_do_you_want_the_smp_calculated? do
  option :weekly_starting
  option :usual_paydates

  save_input_as :smp_calculation_method

  permitted_next_nodes = [
    :maternity_leave_and_pay_result,
    :when_in_the_month_is_the_employee_paid?,
    :when_is_your_employees_next_pay_day?
  ]
  next_node(permitted: permitted_next_nodes) do |response|
    if response == 'usual_paydates'
      if pay_pattern == 'monthly'
        :when_in_the_month_is_the_employee_paid?
      else
        :when_is_your_employees_next_pay_day?
      end
    else
      :maternity_leave_and_pay_result
    end
  end
end

## QM11
date_question :when_is_your_employees_next_pay_day? do
  calculate :next_pay_day do |response|
    calculator.pay_date = response
    calculator.pay_date
  end
{'fraction_non_alphanumeric': 0.06247480854494156, 'fraction_numerical': 0.0048367593712212815, 'mean_word_length': 4.588400900900901, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6645144', 'n_tokens_mistral': 3684, 'n_tokens_neox': 3520, 'n_words': 671}