diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt index 285e83b..cdda6d7 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt @@ -18,16 +18,16 @@ package uk.gov.hmrc.helptosavecalculator import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput import uk.gov.hmrc.helptosavecalculator.utils.monthsSince -open class FirstBonusTermCalculation { +internal class FirstBonusTermCalculation { - protected fun calculateTotalProjectedSavingsIncludeBonuses( + fun calculateTotalProjectedSavingsIncludeBonuses( totalProjectedSavings: Double, totalProjectedBonuses: Double ): Double { return totalProjectedSavings + totalProjectedBonuses } - protected fun calculateAdditionalSavingsThisMonth(input: FirstBonusInput): Double { + fun calculateAdditionalSavingsThisMonth(input: FirstBonusInput): Double { return if (input.regularPayment > input.paidInThisMonth) { input.regularPayment - input.paidInThisMonth } else { @@ -35,7 +35,7 @@ open class FirstBonusTermCalculation { } } - protected fun calculateTotalProjectedSavings( + fun calculateTotalProjectedSavings( input: FirstBonusInput, additionalSavingsThisMonth: Double, monthsLeftInScheme: Int @@ -43,14 +43,14 @@ open class FirstBonusTermCalculation { return input.currentBalance + additionalSavingsThisMonth + (input.regularPayment * monthsLeftInScheme) } - protected fun calculateTotalProjectedBonuses( + fun calculateTotalProjectedBonuses( projectedFirstBonus: Double, projectedFinalBonus: Double ): Double { return projectedFirstBonus + projectedFinalBonus } - protected fun calculateProjectedSavingsFirstBonusPeriod( + fun calculateProjectedSavingsFirstBonusPeriod( input: FirstBonusInput, additionalSavingsThisMonth: Double, monthsLeftInFirstTerm: Int @@ -58,7 +58,7 @@ open class FirstBonusTermCalculation { return input.currentBalance + additionalSavingsThisMonth + (input.regularPayment * monthsLeftInFirstTerm) } - protected fun calculateHighestBalanceFirstBonusPeriod( + fun calculateHighestBalanceFirstBonusPeriod( input: FirstBonusInput, projectedSavingsFirstBonusPeriod: Double ): Double { @@ -67,15 +67,15 @@ open class FirstBonusTermCalculation { } ?: projectedSavingsFirstBonusPeriod } - protected fun calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod: Double): Double { + fun calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod: Double): Double { return highestBalanceFirstBonusPeriod / 2 } - protected fun calculateProjectedAdditionalSavingsFinalBonusPeriod(input: FirstBonusInput): Double { + fun calculateProjectedAdditionalSavingsFinalBonusPeriod(input: FirstBonusInput): Double { return input.regularPayment * 24 } - protected fun calculateProjectedFinalBonus( + fun calculateProjectedFinalBonus( highestBalanceFinalBonusPeriod: Double, highestBalanceFirstBonusPeriod: Double ): Double { @@ -86,7 +86,7 @@ open class FirstBonusTermCalculation { } } - protected fun calculateMonthsLeftInScheme(input: FirstBonusInput): Pair { + fun calculateMonthsLeftInScheme(input: FirstBonusInput): Pair { val startDate = input.accountStartDate.convertToDateTime() val secondTermEndDate = input.secondTermEndDate.convertToDateTime() val firstTermEndDate = input.firstTermEndDate.convertToDateTime() diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt index f9790e2..471bfea 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt @@ -20,7 +20,9 @@ import uk.gov.hmrc.helptosavecalculator.models.FirstBonusCalculatorResponse import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput import uk.gov.hmrc.helptosavecalculator.validation.RegularPaymentValidators -object FirstBonusTermCalculator : FirstBonusTermCalculation() { +object FirstBonusTermCalculator { + + private val calculation = FirstBonusTermCalculation() fun runFirstBonusCalculator(input: FirstBonusInput): FirstBonusCalculatorResponse { return calculateFirstBonus(input) @@ -29,19 +31,25 @@ object FirstBonusTermCalculator : FirstBonusTermCalculation() { private fun calculateFirstBonus(input: FirstBonusInput): FirstBonusCalculatorResponse { validateUserInput(input.regularPayment) - val (monthLeftInScheme, monthLeftInFirstTerm) = calculateMonthsLeftInScheme(input) - val additionalSavingsThisMonth = calculateAdditionalSavingsThisMonth(input) - val totalProjectedSavings = calculateTotalProjectedSavings(input, additionalSavingsThisMonth, monthLeftInScheme) - val projectedSavingsFirstBonusPeriod = calculateProjectedSavingsFirstBonusPeriod(input, + val (monthLeftInScheme, monthLeftInFirstTerm) = calculation.calculateMonthsLeftInScheme(input) + val additionalSavingsThisMonth = calculation.calculateAdditionalSavingsThisMonth(input) + val totalProjectedSavings = calculation.calculateTotalProjectedSavings(input, + additionalSavingsThisMonth, + monthLeftInScheme) + val projectedSavingsFirstBonusPeriod = calculation.calculateProjectedSavingsFirstBonusPeriod(input, additionalSavingsThisMonth, monthLeftInFirstTerm) - val highestBalanceFirstBonusPeriod = calculateHighestBalanceFirstBonusPeriod(input, + val highestBalanceFirstBonusPeriod = calculation.calculateHighestBalanceFirstBonusPeriod(input, projectedSavingsFirstBonusPeriod) - val projectedFirstBonus = calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod) - val projectedAdditionalSavingsFinalBonusPeriod = calculateProjectedAdditionalSavingsFinalBonusPeriod(input) - val projectedFinalBonus = calculateProjectedFinalBonus(totalProjectedSavings, highestBalanceFirstBonusPeriod) - val totalProjectedBonuses = calculateTotalProjectedBonuses(projectedFirstBonus, projectedFinalBonus) - val totalProjectedSavingsIncludingBonuses = calculateTotalProjectedSavingsIncludeBonuses(totalProjectedSavings, + val projectedFirstBonus = calculation.calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod) + val projectedAdditionalSavingsFinalBonusPeriod = + calculation.calculateProjectedAdditionalSavingsFinalBonusPeriod(input) + val projectedFinalBonus = calculation.calculateProjectedFinalBonus(totalProjectedSavings, + highestBalanceFirstBonusPeriod) + val totalProjectedBonuses = calculation.calculateTotalProjectedBonuses(projectedFirstBonus, + projectedFinalBonus) + val totalProjectedSavingsIncludingBonuses = + calculation.calculateTotalProjectedSavingsIncludeBonuses(totalProjectedSavings, totalProjectedBonuses) return FirstBonusCalculatorResponse(