<commit_before>status :draft
satisfies_need "2013"

# Question 1
checkbox_question :is_your_employee_getting? do
  option :statutory_maternity_pay
  option :maternity_allowance
  option :ordinary_statutory_paternity_pay
  option :statutory_adoption_pay

  calculate :paternity_maternity_warning do
    (responses.last.split(",") & %w{ordinary_statutory_paternity_pay statutory_adoption_pay}).any?
  end
  next_node do |response|
    if (response.split(",") & %w{ordinary_statutory_paternity_pay statutory_adoption_pay}).any?
      # Question 2
      :employee_tell_within_limit?
    else
      # Answer 1
      :already_getting_maternity
    end
  end
end

# Question 2
multiple_choice :employee_tell_within_limit? do
	option :yes => :employee_work_different_days? # Question 5
	option :no => :didnt_tell_soon_enough # Answer 3
end

# Question 3
multiple_choice :employee_work_different_days? do
	option :yes => :not_regular_schedule # Answer 4
	option :no => :first_sick_day? # Question 4
end

# Question 4
date_question :first_sick_day? do
  calculate :sick_start_date do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  next_node :last_sick_day?

end

# Question 5
date_question :last_sick_day? do
  calculate :sick_end_date do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  next_node do |response|
    start_date = Date.parse(sick_start_date)
    end_date = Date.parse(response)
    days = (end_date - start_date).to_i

    if days < 1
      # invalid
      raise SmartAnswer::InvalidResponse
    end

    days > 3 ? :last_payday_before_sickness? : :must_be_sick_for_4_days
  end

end

# Question 6
date_question :last_payday_before_sickness? do

  calculate :relevant_period_to do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  calculate :pay_day_offset do
    (Date.parse(relevant_period_to) - 8.weeks).strftime("%e %B %Y")
  end


  next_node do |response|
    payday = Date.parse(response)
    start = Date.parse(sick_start_date)

    unless payday < start
      raise SmartAnswer::InvalidResponse
    end

    :last_payday_before_offset?
  end
end

# Question 7
date_question :last_payday_before_offset? do
  # input plus 1 day = relevant_period_from
  calculate :relevant_period_from do
    (Date.parse(responses.last) + 1.day).strftime("%e %B %Y")
  end
   # You must enter a date on or before [pay_day_offset]
  next_node do |response|
    day = Date.parse(response)
    if day > Date.parse(pay_day_offset)
      raise SmartAnswer::InvalidResponse
    end
    :how_often_pay_employee?
  end
end

# Question 7.4
multiple_choice :how_often_pay_employee? do
  option :weekly
  option :fortnightly
  option :every_4_weeks
  option :monthly
  option :irregularly

  save_input_as :pay_pattern

  calculate :monthly_pattern_payments do
    start_date = Date.parse(relevant_period_from)
    end_date = Date.parse(relevant_period_to)
    Calculators::StatutorySickPayCalculator.months_between(start_date, end_date)
  end

  next_node :on_start_date_8_weeks_paid?
end

# Question 8
multiple_choice :on_start_date_8_weeks_paid? do
  option :yes => :total_employee_earnings? # Question 10
  option :no => :employee_average_earnings? # Question 11
end

# Question 9
money_question :total_employee_earnings? do
  save_input_as :relevant_period_pay
  calculate :relevant_period_awe do
    Calculators::StatutorySickPayCalculator.average_weekly_earnings(
      pay: relevant_period_pay, pay_pattern: pay_pattern, monthly_pattern_payments: monthly_pattern_payments,
      relevant_period_to: relevant_period_to, relevant_period_from: relevant_period_from)
  end

  next_node do |response|
    relevant_period_pay = Money.new(response)
    relevant_pay_awe = Calculators::StatutorySickPayCalculator.average_weekly_earnings(
      pay: relevant_period_pay, pay_pattern: pay_pattern, monthly_pattern_payments: monthly_pattern_payments,
      relevant_period_to: relevant_period_to, relevant_period_from: relevant_period_from)

    if relevant_pay_awe < Calculators::StatutorySickPayCalculator.lower_earning_limit_on(Date.parse(sick_start_date))
      # Answer 5
      :not_earned_enough
    else
      # Question 12
      :off_sick_4_days?
    end
  end

end

# Question 10
money_question :employee_average_earnings? do
  next_node do |response|
    if response < Calculators::StatutorySickPayCalculator.lower_earning_limit_on(Date.parse(sick_start_date))
       # Answer 5
      :not_earned_enough
    else
      # Question 12
      :off_sick_4_days?
    end
  end
end

# Q11
multiple_choice :off_sick_4_days? do
  option :yes => :how_many_days_sick?
  option :no => :usual_work_days?

  calculate :previous_sickness do
    responses.last == "yes"
  end
end

# Q12
value_question :how_many_days_sick? do
  save_input_as :prior_sick_days
  next_node :usual_work_days?
end

# Q13
checkbox_question :usual_work_days? do
  ((1..6).to_a + [0]).each { |n| option n.to_s }

  calculate :calculator do
    calculator = Calculators::StatutorySickPayCalculator.new(prior_sick_days.to_i, Date.parse(sick_start_date), Date.parse(sick_end_date), responses.last.split(","))
  end

  calculate :ssp_payment do
    Money.new(calculator.ssp_payment)
  end

  next_node do |response|
    calculator = Calculators::StatutorySickPayCalculator.new(prior_sick_days.to_i, Date.parse(sick_start_date), Date.parse(sick_end_date), response.split(","))

    days_worked = response.split(',').size<commit_msg>Rewrite array generation for days of week to be neater<commit_after>status :draft
satisfies_need "2013"

# Question 1
checkbox_question :is_your_employee_getting? do
  option :statutory_maternity_pay
  option :maternity_allowance
  option :ordinary_statutory_paternity_pay
  option :statutory_adoption_pay

  calculate :paternity_maternity_warning do
    (responses.last.split(",") & %w{ordinary_statutory_paternity_pay statutory_adoption_pay}).any?
  end
  next_node do |response|
    if (response.split(",") & %w{ordinary_statutory_paternity_pay statutory_adoption_pay}).any?
      # Question 2
      :employee_tell_within_limit?
    else
      # Answer 1
      :already_getting_maternity
    end
  end
end

# Question 2
multiple_choice :employee_tell_within_limit? do
	option :yes => :employee_work_different_days? # Question 5
	option :no => :didnt_tell_soon_enough # Answer 3
end

# Question 3
multiple_choice :employee_work_different_days? do
	option :yes => :not_regular_schedule # Answer 4
	option :no => :first_sick_day? # Question 4
end

# Question 4
date_question :first_sick_day? do
  calculate :sick_start_date do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  next_node :last_sick_day?

end

# Question 5
date_question :last_sick_day? do
  calculate :sick_end_date do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  next_node do |response|
    start_date = Date.parse(sick_start_date)
    end_date = Date.parse(response)
    days = (end_date - start_date).to_i

    if days < 1
      # invalid
      raise SmartAnswer::InvalidResponse
    end

    days > 3 ? :last_payday_before_sickness? : :must_be_sick_for_4_days
  end

end

# Question 6
date_question :last_payday_before_sickness? do

  calculate :relevant_period_to do
    Date.parse(responses.last).strftime("%e %B %Y")
  end

  calculate :pay_day_offset do
    (Date.parse(relevant_period_to) - 8.weeks).strftime("%e %B %Y")
  end


  next_node do |response|
    payday = Date.parse(response)
    start = Date.parse(sick_start_date)

    unless payday < start
      raise SmartAnswer::InvalidResponse
    end

    :last_payday_before_offset?
  end
end

# Question 7
date_question :last_payday_before_offset? do
  # input plus 1 day = relevant_period_from
  calculate :relevant_period_from do
    (Date.parse(responses.last) + 1.day).strftime("%e %B %Y")
  end
   # You must enter a date on or before [pay_day_offset]
  next_node do |response|
    day = Date.parse(response)
    if day > Date.parse(pay_day_offset)
      raise SmartAnswer::InvalidResponse
    end
    :how_often_pay_employee?
  end
end

# Question 7.4
multiple_choice :how_often_pay_employee? do
  option :weekly
  option :fortnightly
  option :every_4_weeks
  option :monthly
  option :irregularly

  save_input_as :pay_pattern

  calculate :monthly_pattern_payments do
    start_date = Date.parse(relevant_period_from)
    end_date = Date.parse(relevant_period_to)
    Calculators::StatutorySickPayCalculator.months_between(start_date, end_date)
  end

  next_node :on_start_date_8_weeks_paid?
end

# Question 8
multiple_choice :on_start_date_8_weeks_paid? do
  option :yes => :total_employee_earnings? # Question 10
  option :no => :employee_average_earnings? # Question 11
end

# Question 9
money_question :total_employee_earnings? do
  save_input_as :relevant_period_pay
  calculate :relevant_period_awe do
    Calculators::StatutorySickPayCalculator.average_weekly_earnings(
      pay: relevant_period_pay, pay_pattern: pay_pattern, monthly_pattern_payments: monthly_pattern_payments,
      relevant_period_to: relevant_period_to, relevant_period_from: relevant_period_from)
  end

  next_node do |response|
    relevant_period_pay = Money.new(response)
    relevant_pay_awe = Calculators::StatutorySickPayCalculator.average_weekly_earnings(
      pay: relevant_period_pay, pay_pattern: pay_pattern, monthly_pattern_payments: monthly_pattern_payments,
      relevant_period_to: relevant_period_to, relevant_period_from: relevant_period_from)

    if relevant_pay_awe < Calculators::StatutorySickPayCalculator.lower_earning_limit_on(Date.parse(sick_start_date))
      # Answer 5
      :not_earned_enough
    else
      # Question 12
      :off_sick_4_days?
    end
  end

end

# Question 10
money_question :employee_average_earnings? do
  next_node do |response|
    if response < Calculators::StatutorySickPayCalculator.lower_earning_limit_on(Date.parse(sick_start_date))
       # Answer 5
      :not_earned_enough
    else
      # Question 12
      :off_sick_4_days?
    end
  end
end

# Q11
multiple_choice :off_sick_4_days? do
  option :yes => :how_many_days_sick?
  option :no => :usual_work_days?

  calculate :previous_sickness do
    responses.last == "yes"
  end
end

# Q12
value_question :how_many_days_sick? do
  save_input_as :prior_sick_days
  next_node :usual_work_days?
end

# Q13
checkbox_question :usual_work_days? do
  %w{1 2 3 4 5 6 0}.each { |n| option n.to_s }

  calculate :calculator do
    calculator = Calculators::StatutorySickPayCalculator.new(prior_sick_days.to_i, Date.parse(sick_start_date), Date.parse(sick_end_date), responses.last.split(","))
  end

  calculate :ssp_payment do
    Money.new(calculator.ssp_payment)
  end

  next_node do |response|
    calculator = Calculators::StatutorySickPayCalculator.new(prior_sick_days.to_i, Date.parse(sick_start_date), Date.parse(sick_end_date), response.split(","))

    days_worked = response.split(',').size
{'fraction_non_alphanumeric': 0.08087220535467844, 'fraction_numerical': 0.010304535835863465, 'mean_word_length': 4.69408067050812, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '814926', 'n_tokens_mistral': 4038, 'n_tokens_neox': 3743, 'n_words': 769}