import matplotlib.pyplot as plt  # For graphics
%matplotlib inline

from openfisca_tunisia.tunisia_taxbenefitsystem import TunisiaTaxBenefitSystem


tax_benefit_system = TunisiaTaxBenefitSystem()

"""
Explanation: Démonstration - openfisca-tunisia
Retrouvez son code source ici : https://github.com/openfisca/openfisca-tunisia
Chargement des bibliothèques et initialisation
End of explanation
"""


from openfisca_tunisia.scenarios import init_single_entity

years = [2012, 2013, 2014, 2017, 2018]
salaire_de_base_max = 20000
simulation = init_single_entity(tax_benefit_system.new_scenario(),
    period = 2014,
    axes = [
        [
            dict(
                # variable 'name' evolution between ['min', 'max'] in 'count' steps for 'period'
                count = 1000,
                name = 'salaire_de_base',
                min = 0,
                max = salaire_de_base_max,
                period = year,
                )
            for year in years
            ]
        ],
    parent1 = dict(age = 40),
    ).new_simulation()

salaire_imposable_by_year = dict(
    (year, simulation.calculate_add('salaire_imposable', period = year)) 
    for year in years
    )
irpp_by_year = dict(
    (year, simulation.calculate('irpp', period = year)) 
    for year in years
    )

plt.figure(figsize=(12, 8))
salaire_imposable = salaire_imposable_by_year[2014]
for year in years:
    plt.plot(salaire_imposable, -irpp_by_year[year], label='impôt sur le revenu {}'.format(year))
    plt.xlabel('Salaire')
    plt.legend()


"""
Explanation: Evolution du barème de l'impôt sur le revenu
End of explanation
"""


from openfisca_tunisia.scenarios import init_single_entity

salaire_de_base_max = 20000
simulations = [
    init_single_entity(tax_benefit_system.new_scenario(),
        period = 2017,
        parent1 = dict(age = 40, regime_securite_sociale = regime_securite_sociale, salaire_de_base = 20000),
        ).new_simulation()
    for regime_securite_sociale in ['rsna', 'salarie_cnrps']  # Salarié du privé ou fonctionnaire
    ]

variables = ['salaire_super_brut', 'salaire_de_base', 'salaire_imposable', 'salaire_net_a_payer']
for index, simulation in enumerate(simulations):
    print("Simulation " + str(index))
    for variable in variables:
        print(
            "{}: {}".format(
                variable,
                simulation.calculate_add(variable, period = 2017)
                )
            )

# Add your code here :)

"""
Explanation: Coût du travail et salaire net
End of explanation
"""


