# Path: pynYNAB/schema/budget.py
# class Payee(Base, BudgetEntity):
#     auto_fill_amount = Column(AmountType)
#     auto_fill_amount_enabled = Column(String)
#     auto_fill_memo = Column(String)
#     auto_fill_memo_enabled = Column(String)
#     auto_fill_subcategory_enabled = Column(String)
#     auto_fill_subcategory_id = Column(ForeignKey('subcategory.id'))
#     auto_fill_subcategory = relationship('SubCategory', foreign_keys=auto_fill_subcategory_id)
#     enabled = Column(Boolean, default=True)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     internal_name = Column(String)
#     name = Column(String)
#     rename_on_import_enabled = Column(String)
# 
# 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)


import csv
import logging
import os
import sys
from collections import namedtuple
from datetime import datetime
from pynYNAB.ClientFactory import clientfromargs
from pynYNAB.schema.budget import Payee, Transaction


scriptsdir = os.path.dirname(os.path.abspath(__file__))
schemas_dir = os.path.join(scriptsdir, 'csv_schemas')

LOG = logging.getLogger(__name__)


def verify_csvimport(schema, accountname=None):
    if 'account' not in schema.headers and accountname is None:
        LOG.error('schema headers: %s' % schema.headers)
        LOG.error('This schema does not have an account column and no account name was provided')
        exit(-1)


class CsvImportArgs(object):
    def __init__(self, csv_file, schema, account_name=None, import_duplicates=False):
        self.csv_file = csv_file

# Path: pynYNAB/schema/budget.py
# class Payee(Base, BudgetEntity):
#     auto_fill_amount = Column(AmountType)
#     auto_fill_amount_enabled = Column(String)
#     auto_fill_memo = Column(String)
#     auto_fill_memo_enabled = Column(String)
#     auto_fill_subcategory_enabled = Column(String)
#     auto_fill_subcategory_id = Column(ForeignKey('subcategory.id'))
#     auto_fill_subcategory = relationship('SubCategory', foreign_keys=auto_fill_subcategory_id)
#     enabled = Column(Boolean, default=True)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     internal_name = Column(String)
#     name = Column(String)
#     rename_on_import_enabled = Column(String)
# 
# 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: pynYNAB/scripts/csvimport.py
import csv
import logging
import os
import sys
from collections import namedtuple
from datetime import datetime
from pynYNAB.ClientFactory import clientfromargs
from pynYNAB.schema.budget import Payee, Transaction



scriptsdir = os.path.dirname(os.path.abspath(__file__))
schemas_dir = os.path.join(scriptsdir, 'csv_schemas')

LOG = logging.getLogger(__name__)


def verify_csvimport(schema, accountname=None):
    if 'account' not in schema.headers and accountname is None:
        LOG.error('schema headers: %s' % schema.headers)
        LOG.error('This schema does not have an account column and no account name was provided')
        exit(-1)


class CsvImportArgs(object):
    def __init__(self, csv_file, schema, account_name=None, import_duplicates=False):
        self.csv_file = csv_file

        self.schema = schema