# Path: lib/fpos/core.py
# def money(value):
#     return "{:.2f}".format(value)
# 
# Path: lib/fpos/core.py
# def money(value):
# def lcs(a, b):


import argparse
import csv
import sys
import dateutil.parser as dp
import re
from datetime import datetime
from .core import money
from .core import date_fmt
from itertools import chain
    # NAB format:
    #
    # Date, Amount, Ref #,, Description, Merchant, Remaining Balance
    # 28-Apr-14,-64.67,071644731756,,CREDIT CARD PURCHASE,BP CRAFERS 9125 CRAFERS,-169.28,
    def _gen():
        for l in csv:
            if l:
                try:
                    ir_date = datetime.strptime(l[0], _nab_date_fmt).strftime(date_fmt)
                except ValueError:
                    ir_date = datetime.strptime(l[0], _nab_2018_date_fmt).strftime(date_fmt)
                ir_amount = money(float(l[1]))
                ir_description = " ".join(e for e in l[4:6] if (e is not None and "" != e ))
                yield [ ir_date, ir_amount, ir_description ]
    return _gen()


def transform_nab_2018(csv, args=None):
    # NAB 2018 format:
    #
    # Date, Amount,,,Transfer Type, Description, Remaining Balance
    # "07 Feb 18","-12.00",,,"TRANSFER DEBIT","INTERNET TRANSFER   Lunch","+500.00"
    #
    # The date format is different to 2018, and there's one less column. Also
    # flips the bird to data types, everything is a string. And now
    # currency-style value formatting means locale-specific separators such as
    # ',' get in the way of parsing the transaction value.
    def _gen():
        for l in csv:
            if l:

# Path: lib/fpos/core.py
# def money(value):
#     return "{:.2f}".format(value)
# 
# Path: lib/fpos/core.py
# def money(value):
# def lcs(a, b):


# Path: lib/fpos/transform.py
import argparse
import csv
import sys
import dateutil.parser as dp
import re
from datetime import datetime
from .core import money
from .core import date_fmt
from itertools import chain

    # NAB format:
    #
    # Date, Amount, Ref #,, Description, Merchant, Remaining Balance
    # 28-Apr-14,-64.67,071644731756,,CREDIT CARD PURCHASE,BP CRAFERS 9125 CRAFERS,-169.28,
    def _gen():
        for l in csv:
            if l:
                try:
                    ir_date = datetime.strptime(l[0], _nab_date_fmt).strftime(date_fmt)
                except ValueError:
                    ir_date = datetime.strptime(l[0], _nab_2018_date_fmt).strftime(date_fmt)
                ir_amount = money(float(l[1]))
                ir_description = " ".join(e for e in l[4:6] if (e is not None and "" != e ))
                yield [ ir_date, ir_amount, ir_description ]
    return _gen()


def transform_nab_2018(csv, args=None):
    # NAB 2018 format:
    #
    # Date, Amount,,,Transfer Type, Description, Remaining Balance
    # "07 Feb 18","-12.00",,,"TRANSFER DEBIT","INTERNET TRANSFER   Lunch","+500.00"
    #
    # The date format is different to 2018, and there's one less column. Also
    # flips the bird to data types, everything is a string. And now
    # currency-style value formatting means locale-specific separators such as
    # ',' get in the way of parsing the transaction value.
    def _gen():
        for l in csv:
            if l:

                ir_date = datetime.strptime(l[0], _nab_2018_date_fmt).strftime(date_fmt)