use crate::tax_years::TaxYear;
pub fn national_insurance(
gross_income: f64,
year: &TaxYear,
_personal_allowance: Option<u32>,
) -> f64 {
let gross_income_pence = (gross_income * 100.0).round() as u32;
let p_thold = year.ni_primary_threshold * 100;
let u_thold = year.ni_upper_earnings_limit * 100;
let taxable_income = gross_income_pence.saturating_sub(p_thold);
let mut tax = 0;
if gross_income_pence <= u_thold {
tax += (taxable_income as f64 * year.ni_primary_rate).round() as u32;
} else {
tax += ((u_thold - p_thold) as f64 * year.ni_primary_rate).round() as u32;
tax += ((taxable_income - (u_thold - p_thold)) as f64 * year.ni_upper_rate).round() as u32;
}
(tax as f64) / 100.0
}