# Path: pynYNAB/Client.py
# LOG = logging.getLogger(__name__)
# class nYnabClient(object):
#     def __new__(cls, *args, **kwargs):
# 
# Path: pynYNAB/schema/budget.py
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)


from memory_profiler import memory_usage, profile
from sqlalchemy import create_engine
from pynYNAB.Client import clientfromargs
from pynYNAB.schema.budget import Transaction



class Args(object):
    email='email'
    password='password'
    nynabconnection=None
    budgetname='test budget'

client = clientfromargs(Args(),sync=False)
#client.session.bind.echo = True

@profile
def func():
    print('test_sync')
    for i in range(0,5000):
        client.budget.be_transactions.append(Transaction())
    client.session.commit()
    client.budgetClient.clear_changed_entities()
    print('Entities in the client: %i'%(sum([len(getattr(client.budget, f)) for f in client.budget.listfields]) +
          sum([len(getattr(client.catalog, f)) for f in client.catalog.listfields])))
    pass

if __name__ == '__main__':

# Path: pynYNAB/Client.py
# LOG = logging.getLogger(__name__)
# class nYnabClient(object):
#     def __new__(cls, *args, **kwargs):
# 
# Path: pynYNAB/schema/budget.py
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)


# Path: testscripts/test_memory.py
from memory_profiler import memory_usage, profile
from sqlalchemy import create_engine
from pynYNAB.Client import clientfromargs
from pynYNAB.schema.budget import Transaction




class Args(object):
    email='email'
    password='password'
    nynabconnection=None
    budgetname='test budget'

client = clientfromargs(Args(),sync=False)
#client.session.bind.echo = True

@profile
def func():
    print('test_sync')
    for i in range(0,5000):
        client.budget.be_transactions.append(Transaction())
    client.session.commit()
    client.budgetClient.clear_changed_entities()
    print('Entities in the client: %i'%(sum([len(getattr(client.budget, f)) for f in client.budget.listfields]) +
          sum([len(getattr(client.catalog, f)) for f in client.catalog.listfields])))
    pass

if __name__ == '__main__':

    func()