# Path: alm/Balance_Sheets.py
# class Balance_Sheets(object):
#     """
#         DOCUMENTATION WILL BE COMPLETED LATER
#     """
#     def __init__(self):
#         self.assets = {}
#         self.liabilities = {}
#         self.cash_flows_in = {}
#         self.cash_flows_out = {}
# 
#     def update(self, key_lv1, key_lv2, value):
#         if key_lv1 == 'assets':
#             self.assets[key_lv2] = value
#         elif key_lv1 == 'liabilities':
#             self.liabilities[key_lv2] = value
#         elif key_lv1 == 'cash_flows_in':
#             self.cash_flows_in[key_lv2] = value
#         elif key_lv1 == 'cash_flows_out':
#             self.cash_flows_out[key_lv2] = value
#         else:
#             raise ValueError("Could not find ", key_lv1)
# 
#     def get_value(self, key_lv1, key_lv2):
#         if key_lv1 == 'assets':
#             resu = self.assets[key_lv2]
#         elif key_lv1 == 'liabilities':
#             resu = self.liabilities[key_lv2]
#         elif key_lv1 == 'cash_flows_in':
#             resu = self.cash_flows_in[key_lv2]
#         elif key_lv1 == 'cash_flows_out':
#             resu = self.cash_flows_out[key_lv2]
#         else:
#             raise ValueError("Could not find ", key_lv1)
#         return resu
# 
#     def get_cash_flow(self):
#         return sum(self.cash_flows_in[key] for key in self.cash_flows_in.keys()) - sum(self.cash_flows_out[key] for key in self.cash_flows_out.keys())


from ..liability.liability_data.Liabilities_data_m import Liabilities_data_m
from ..liability.liability_data.Liabilities_data import Liabilities_data
from ..esg.ESG_RN import ESG_RN
from .Balance_Sheets import Balance_Sheets
import numpy as np
                1. traj_i:
                    Type: int
                    Function: the i-th economic scenario
                2. time_step:
                    Type: int
                    Function: valuation date
        """
        # ===================================================================================
        # Assets: Update Cash
        # ===================================================================================
        self.additional_fund = 0
        self.distributed_wealth = 0
        self.assets.add_cash(amount = self.assets.cash[-1])
        
        cash_return_rate = self.assets.ESG_RN.scenarios[traj_i]['IR_curves'][time_step-1, 0]
        self.cash_revenue = (self.liabilities.technical_provision.profit_sharing_reserve[-1] + self.assets.cash[-1])*cash_return_rate
        
        self.available_wealth = self.cash_revenue + self.assets.asset_income[time_step-1]['PMVR_hors_obligation'] + self.assets.asset_income[time_step-1]['PMVR_obligation_TF']
        
        # ===================================================================================
        # Liabilities: Initilize Own Fund, Capitalization Reserve and PRE
        # ===================================================================================
                
        self.liabilities.own_fund.append(self.liabilities.own_fund[-1]*(1+cash_return_rate))
        self.liabilities.capitalization_reserve.append(self.liabilities.capitalization_reserve[-1]*(1+cash_return_rate))
        self.liabilities.PRE.append(self.liabilities.PRE[-1]*(1+cash_return_rate))
        
        Cash_Return = self.cash_revenue
        # ==========================================
        # Initialize Balance Sheet

# Path: alm/Balance_Sheets.py
# class Balance_Sheets(object):
#     """
#         DOCUMENTATION WILL BE COMPLETED LATER
#     """
#     def __init__(self):
#         self.assets = {}
#         self.liabilities = {}
#         self.cash_flows_in = {}
#         self.cash_flows_out = {}
# 
#     def update(self, key_lv1, key_lv2, value):
#         if key_lv1 == 'assets':
#             self.assets[key_lv2] = value
#         elif key_lv1 == 'liabilities':
#             self.liabilities[key_lv2] = value
#         elif key_lv1 == 'cash_flows_in':
#             self.cash_flows_in[key_lv2] = value
#         elif key_lv1 == 'cash_flows_out':
#             self.cash_flows_out[key_lv2] = value
#         else:
#             raise ValueError("Could not find ", key_lv1)
# 
#     def get_value(self, key_lv1, key_lv2):
#         if key_lv1 == 'assets':
#             resu = self.assets[key_lv2]
#         elif key_lv1 == 'liabilities':
#             resu = self.liabilities[key_lv2]
#         elif key_lv1 == 'cash_flows_in':
#             resu = self.cash_flows_in[key_lv2]
#         elif key_lv1 == 'cash_flows_out':
#             resu = self.cash_flows_out[key_lv2]
#         else:
#             raise ValueError("Could not find ", key_lv1)
#         return resu
# 
#     def get_cash_flow(self):
#         return sum(self.cash_flows_in[key] for key in self.cash_flows_in.keys()) - sum(self.cash_flows_out[key] for key in self.cash_flows_out.keys())


# Path: alm/ALM.py
from ..liability.liability_data.Liabilities_data_m import Liabilities_data_m
from ..liability.liability_data.Liabilities_data import Liabilities_data
from ..esg.ESG_RN import ESG_RN
from .Balance_Sheets import Balance_Sheets
import numpy as np

                1. traj_i:
                    Type: int
                    Function: the i-th economic scenario
                2. time_step:
                    Type: int
                    Function: valuation date
        """
        # ===================================================================================
        # Assets: Update Cash
        # ===================================================================================
        self.additional_fund = 0
        self.distributed_wealth = 0
        self.assets.add_cash(amount = self.assets.cash[-1])
        
        cash_return_rate = self.assets.ESG_RN.scenarios[traj_i]['IR_curves'][time_step-1, 0]
        self.cash_revenue = (self.liabilities.technical_provision.profit_sharing_reserve[-1] + self.assets.cash[-1])*cash_return_rate
        
        self.available_wealth = self.cash_revenue + self.assets.asset_income[time_step-1]['PMVR_hors_obligation'] + self.assets.asset_income[time_step-1]['PMVR_obligation_TF']
        
        # ===================================================================================
        # Liabilities: Initilize Own Fund, Capitalization Reserve and PRE
        # ===================================================================================
                
        self.liabilities.own_fund.append(self.liabilities.own_fund[-1]*(1+cash_return_rate))
        self.liabilities.capitalization_reserve.append(self.liabilities.capitalization_reserve[-1]*(1+cash_return_rate))
        self.liabilities.PRE.append(self.liabilities.PRE[-1]*(1+cash_return_rate))
        
        Cash_Return = self.cash_revenue
        # ==========================================
        # Initialize Balance Sheet

        self.balance_sheets.append(Balance_Sheets())