|
| 1 | +namespace CompoundCalc.Models.Responses; |
| 2 | + |
| 3 | +public sealed record CarLoanAmortizationEntry( |
| 4 | + int Month, |
| 5 | + decimal Payment, |
| 6 | + decimal Principal, |
| 7 | + decimal Interest, |
| 8 | + decimal RemainingBalance); |
| 9 | + |
| 10 | +public sealed record CarLoanResult( |
| 11 | + decimal VehiclePrice, |
| 12 | + decimal CashDownPayment, |
| 13 | + decimal TradeInValue, |
| 14 | + decimal TradeInPayoff, |
| 15 | + decimal NetTradeInCredit, |
| 16 | + decimal TotalUpfrontCredit, |
| 17 | + decimal SalesTax, |
| 18 | + decimal Fees, |
| 19 | + decimal Rebate, |
| 20 | + decimal FinancedExtras, |
| 21 | + decimal AmountFinanced, |
| 22 | + decimal AnnualRatePercent, |
| 23 | + int TermMonths, |
| 24 | + decimal MonthlyPayment, |
| 25 | + decimal TotalPaid, |
| 26 | + decimal TotalInterest, |
| 27 | + string AmountFinancedDisplay, |
| 28 | + string MonthlyPaymentDisplay, |
| 29 | + string TotalPaidDisplay, |
| 30 | + string TotalInterestDisplay, |
| 31 | + string TotalUpfrontCreditDisplay, |
| 32 | + string NetTradeInCreditDisplay, |
| 33 | + string CalculationVersion, |
| 34 | + IReadOnlyList<CarLoanAmortizationEntry> AmortizationSchedule) |
| 35 | +{ |
| 36 | + public static CarLoanResult Create( |
| 37 | + decimal vehiclePrice, |
| 38 | + decimal cashDownPayment, |
| 39 | + decimal tradeInValue, |
| 40 | + decimal tradeInPayoff, |
| 41 | + decimal netTradeInCredit, |
| 42 | + decimal totalUpfrontCredit, |
| 43 | + decimal salesTax, |
| 44 | + decimal fees, |
| 45 | + decimal rebate, |
| 46 | + decimal financedExtras, |
| 47 | + decimal amountFinanced, |
| 48 | + decimal annualRatePercent, |
| 49 | + int termMonths, |
| 50 | + decimal monthlyPayment, |
| 51 | + decimal totalPaid, |
| 52 | + decimal totalInterest, |
| 53 | + IReadOnlyList<CarLoanAmortizationEntry> amortizationSchedule, |
| 54 | + Func<decimal, string> currencyFormatter, |
| 55 | + string calculationVersion) |
| 56 | + { |
| 57 | + var roundedAmountFinanced = Math.Round(amountFinanced, 2, MidpointRounding.ToEven); |
| 58 | + var roundedMonthlyPayment = Math.Round(monthlyPayment, 2, MidpointRounding.ToEven); |
| 59 | + var roundedTotalPaid = Math.Round(totalPaid, 2, MidpointRounding.ToEven); |
| 60 | + var roundedTotalInterest = Math.Round(totalInterest, 2, MidpointRounding.ToEven); |
| 61 | + var roundedTotalUpfrontCredit = Math.Round(totalUpfrontCredit, 2, MidpointRounding.ToEven); |
| 62 | + var roundedNetTradeInCredit = Math.Round(netTradeInCredit, 2, MidpointRounding.ToEven); |
| 63 | + |
| 64 | + return new CarLoanResult( |
| 65 | + VehiclePrice: vehiclePrice, |
| 66 | + CashDownPayment: cashDownPayment, |
| 67 | + TradeInValue: tradeInValue, |
| 68 | + TradeInPayoff: tradeInPayoff, |
| 69 | + NetTradeInCredit: roundedNetTradeInCredit, |
| 70 | + TotalUpfrontCredit: roundedTotalUpfrontCredit, |
| 71 | + SalesTax: Math.Round(salesTax, 2, MidpointRounding.ToEven), |
| 72 | + Fees: Math.Round(fees, 2, MidpointRounding.ToEven), |
| 73 | + Rebate: Math.Round(rebate, 2, MidpointRounding.ToEven), |
| 74 | + FinancedExtras: Math.Round(financedExtras, 2, MidpointRounding.ToEven), |
| 75 | + AmountFinanced: roundedAmountFinanced, |
| 76 | + AnnualRatePercent: annualRatePercent, |
| 77 | + TermMonths: termMonths, |
| 78 | + MonthlyPayment: roundedMonthlyPayment, |
| 79 | + TotalPaid: roundedTotalPaid, |
| 80 | + TotalInterest: roundedTotalInterest, |
| 81 | + AmountFinancedDisplay: currencyFormatter(roundedAmountFinanced), |
| 82 | + MonthlyPaymentDisplay: currencyFormatter(roundedMonthlyPayment), |
| 83 | + TotalPaidDisplay: currencyFormatter(roundedTotalPaid), |
| 84 | + TotalInterestDisplay: currencyFormatter(roundedTotalInterest), |
| 85 | + TotalUpfrontCreditDisplay: currencyFormatter(roundedTotalUpfrontCredit), |
| 86 | + NetTradeInCreditDisplay: currencyFormatter(roundedNetTradeInCredit), |
| 87 | + CalculationVersion: calculationVersion, |
| 88 | + AmortizationSchedule: amortizationSchedule); |
| 89 | + } |
| 90 | +} |
0 commit comments