import matplotlib.pyplot as plt
import numpy as np

def between(a, b, x):
    max_amount = (b - a)
    return min(max_amount, max(0, x - a))

class Tax:
    def __init__(self, begin_amount, end_amount, tax_rate):
        self.begin_amount = begin_amount
        self.end_amount = end_amount
        self.tax_rate = tax_rate

    def __call__(self, money):
        amount_in_bracket = between(self.begin_amount, self.end_amount, money)
        return amount_in_bracket * self.tax_rate

taxes = [Tax(0, 20142, 0.3655),
         Tax(20142, 33994, 0.4085),
         Tax(33994, 68507, 0.4085),
         Tax(68507, float('inf'), 0.5195)]

incomes = []
taxed_incomes = []


for i in range(0, 2000):
    money = 50 * i
    tax_costs = 0

    belastbaar_inkomen = money

    if (money < 20384):
        belastbaar_inkomen -= 2477
    elif (money < 68507):
        algemene_heffingskorting = 2477 - (0.05147 * (belastbaar_inkomen - 20384))
        belastbaar_inkomen -= algemene_heffingskorting

    if (money < 9694):
        belastbaar_inkomen -= 0.01754 * money
    elif (money < 20940):
        ak = 170 + .28712 * (money - 9694)
        belastbaar_inkomen -= ak
    elif (money < 34060):
        belastbaar_inkomen -= 3399
    elif (money < 90710):
        belastbaar_inkomen -= max(0, 3399 - 0.06 * (money - 34060))

    belastbaar_inkomen = max(0, belastbaar_inkomen)

    for tax in taxes:
        tax_costs += tax(belastbaar_inkomen)

    incomes.append(money)
    taxed_incomes.append(money - tax_costs)

plt.plot(incomes, taxed_incomes)

plt.xlabel('Income')
plt.ylabel('Income after taxes')

plt.title("Effect of tax brackets on different incomes")
plt.show()
